1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct ProjectConfig {
5 pub name: String,
6 pub path: String,
7 pub database: Database,
8 pub auth_method: AuthMethod,
9 pub include_google_oauth: bool,
10 pub install_sqlx: bool,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
14pub enum Database {
15 Postgres,
16 MySql,
17 Sqlite,
18 MongoDb,
19}
20
21impl Database {
22 pub fn as_str(&self) -> &'static str {
23 match self {
24 Database::Postgres => "postgres",
25 Database::MySql => "mysql",
26 Database::Sqlite => "sqlite",
27 Database::MongoDb => "mongodb",
28 }
29 }
30
31 pub fn connection_string_template(&self) -> &'static str {
32 match self {
33 Database::Postgres => "postgresql://user:password@localhost/dbname",
34 Database::MySql => "mysql://user:password@localhost/dbname",
35 Database::Sqlite => "sqlite://./database.db",
36 Database::MongoDb => "mongodb://localhost:27017/dbname",
37 }
38 }
39
40 pub fn sqlx_feature(&self) -> Option<&'static str> {
41 match self {
42 Database::Postgres => Some("postgres"),
43 Database::MySql => Some("mysql"),
44 Database::Sqlite => Some("sqlite"),
45 Database::MongoDb => None,
46 }
47 }
48}
49
50#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
51pub enum AuthMethod {
52 Jwt,
53 Session,
54 Both,
55}
56
57impl AuthMethod {
58 pub fn supports_jwt(&self) -> bool {
59 matches!(self, AuthMethod::Jwt | AuthMethod::Both)
60 }
61
62 pub fn supports_session(&self) -> bool {
63 matches!(self, AuthMethod::Session | AuthMethod::Both)
64 }
65
66 pub fn as_str(&self) -> &'static str {
67 match self {
68 AuthMethod::Jwt => "jwt",
69 AuthMethod::Session => "session",
70 AuthMethod::Both => "both",
71 }
72 }
73}