You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
flotte-user-management/src/database/roles.rs

43 lines
1.2 KiB
Rust

use crate::database::role_permissions::RolePermissions;
use crate::database::{DatabaseError, DatabaseResult, RedisConnection, Table};
use postgres::Client;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct Roles {
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
role_permission: RolePermissions,
}
impl Table for Roles {
fn new(
database_connection: Arc<Mutex<Client>>,
redis_connection: Arc<Mutex<RedisConnection>>,
) -> Self {
Self {
role_permission: RolePermissions::new(
Arc::clone(&database_connection),
Arc::clone(&redis_connection),
),
database_connection,
redis_connection,
}
}
fn init(&self) -> DatabaseResult<()> {
self.database_connection
.lock()
.unwrap()
.batch_execute(
"
CREATE TABLE IF NOT EXISTS roles (
id SERIAL PRIMARY KEY,
name VARCHAR(128) UNIQUE NOT NULL,
description VARCHAR(512)
);",
)
.map_err(|e| DatabaseError::Postgres(e))
}
}