Skip to content

Commit

Permalink
fixbug:rbatis init sql
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Jan 21, 2025
1 parent 56fd615 commit 2b92ee9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ async fn main() -> Result<()> {
}
}
Ok(())
}
}
9 changes: 0 additions & 9 deletions templates/classic/_data/table_mysql.sql

This file was deleted.

9 changes: 0 additions & 9 deletions templates/classic/_data/table_postgres.sql

This file was deleted.

9 changes: 0 additions & 9 deletions templates/classic/_data/table_sqlite.sql

This file was deleted.

26 changes: 26 additions & 0 deletions templates/classic/rbatis/data/init.sql.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% if db_type == "sqlite" %}
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY NOT NULL,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(511) NOT NULL
);
INSERT OR IGNORE INTO users (id, username, password)
VALUES ('cdd0e080-5bb1-4442-b6f7-2ba60dbd0555', 'zhangsan', '$argon2id$v=19$m=19456,t=2,p=1$rcosL5pOPdA2c7i4ZuLA4Q$s0JGh78UzMmu1qZMpVUA3b8kWYLXcZhw7uBfwhYDJ4A');
{% elsif db_type == "postgres" %}
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(255) PRIMARY KEY NOT NULL,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(511) NOT NULL
);
INSERT INTO users (id, username, password)
VALUES ('cdd0e080-5bb1-4442-b6f7-2ba60dbd0555', 'zhangsan', '$argon2id$v=19$m=19456,t=2,p=1$rcosL5pOPdA2c7i4ZuLA4Q$s0JGh78UzMmu1qZMpVUA3b8kWYLXcZhw7uBfwhYDJ4A')
ON CONFLICT DO NOTHING;
{% elsif db_type == "mysql" %}
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(255) PRIMARY KEY NOT NULL,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(511) NOT NULL
);
INSERT IGNORE INTO users (id, username, password)
VALUES ('cdd0e080-5bb1-4442-b6f7-2ba60dbd0555', 'zhangsan', '$argon2id$v=19$m=19456,t=2,p=1$rcosL5pOPdA2c7i4ZuLA4Q$s0JGh78UzMmu1qZMpVUA3b8kWYLXcZhw7uBfwhYDJ4A');
{% endif %}
10 changes: 5 additions & 5 deletions templates/classic/rbatis/src/db/mod.rs.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ pub async fn init(config: &DbConfig) {
{%- if db_type == "sqlite" %}
rb.init(rbdc_sqlite::driver::SqliteDriver {}, &config.url)
.unwrap();
let sql_file = "./data/table_sqlite.sql";
let sql_file = "./data/init.sql";
{%- elsif db_type == "postgres" %}
rb.init(rbdc_sqlite::driver::PostgresDriver {}, &config.url)
rb.init(rbdc_pg::driver::PgDriver {}, &config.url)
.unwrap();
let sql_file = "./data/table_postgres.sql";
let sql_file = "./data/init.sql";
{%- elsif db_type == "mysql" %}
rb.init(rbdc_sqlite::driver::SqliteDriver {}, &config.url)
rb.init(rbdc_mysql::driver::MysqlDriver {}, &config.url)
.unwrap();
let sql_file = "./data/table_mysql.sql";
let sql_file = "./data/init.sql";
{%- endif %}

if sql_file != "" {
Expand Down

0 comments on commit 2b92ee9

Please sign in to comment.