Browse Source

Finally creating the file

master
Julio Biason 4 years ago
parent
commit
7a9e14145f
  1. 5
      sqlxtest/db/migrations/202105261221_create_table.sql
  2. 15
      sqlxtest/src/main.rs

5
sqlxtest/db/migrations/202105261221_create_table.sql

@ -0,0 +1,5 @@
-- Create table
CREATE TABLE testing (
id TEXT PRIMARY KEY,
label TEXT
)

15
sqlxtest/src/main.rs

@ -1,9 +1,18 @@
use sqlx::pool::Pool; use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::Sqlite; use sqlx::sqlite::SqlitePoolOptions;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), sqlx::Error> { async fn main() -> Result<(), sqlx::Error> {
let pool = Pool::<Sqlite>::connect("sqlite::memory:").await?; println!("Open");
let pool = SqlitePoolOptions::new()
.connect_with(
SqliteConnectOptions::new()
.filename("testing.sqlite")
.create_if_missing(true),
)
.await?;
println!("Migrate");
sqlx::migrate!("db/migrations").run(&pool).await?; sqlx::migrate!("db/migrations").run(&pool).await?;
println!("Done");
Ok(()) Ok(())
} }

Loading…
Cancel
Save