diff --git a/sqlx-cli/Cargo.toml b/sqlx-cli/Cargo.toml index 27f578c2..8e374831 100644 --- a/sqlx-cli/Cargo.toml +++ b/sqlx-cli/Cargo.toml @@ -2,18 +2,18 @@ name = "sqlx-cli" version = "0.0.1" description = "Command-line utility for SQLx, the Rust SQL toolkit." -authors = [ - "Jesper Axelsson ", - "Austin Bonander " # austin@launchbadge.com -] edition = "2018" readme = "README.md" homepage = "https://github.com/launchbadge/sqlx" repository = "https://github.com/launchbadge/sqlx" -keywords = ["database", "postgres", "database-management", "migration"] -categories = ["database", "command-line-utilities"] +keywords = [ "database", "postgres", "database-management", "migration"] +categories = [ "database", "command-line-utilities" ] license = "MIT OR Apache-2.0" default-run = "sqlx" +authors = [ + "Jesper Axelsson ", + "Austin Bonander " +] [[bin]] name = "sqlx" diff --git a/sqlx-cli/README.md b/sqlx-cli/README.md index 8bd25a6d..f2346887 100644 --- a/sqlx-cli/README.md +++ b/sqlx-cli/README.md @@ -3,10 +3,14 @@ SQLx's associated command-line utility for managing databases, migrations, and enabling "offline" mode with `sqlx::query!()` and friends. -### Installation +### Install ```bash +# supports all databases supported by SQLx $ cargo install sqlx-cli + +# only for postgres +$ cargo install sqlx-cli --no-default-features --features postgres ``` ### Commands diff --git a/sqlx-cli/src/lib.rs b/sqlx-cli/src/lib.rs index c4b93dd2..6d119e3c 100644 --- a/sqlx-cli/src/lib.rs +++ b/sqlx-cli/src/lib.rs @@ -8,9 +8,7 @@ mod db; mod migration; mod prepare; -/// Sqlx commandline tool #[derive(StructOpt, Debug)] -#[structopt(name = "Sqlx")] pub enum Command { #[structopt(alias = "mig")] Migrate(MigrationCommand), @@ -44,23 +42,22 @@ pub enum Command { }, } -/// Adds and runs migrations. Alias: mig +/// Generate and run migrations #[derive(StructOpt, Debug)] -#[structopt(name = "Sqlx migrator")] pub enum MigrationCommand { - /// Add new migration with name _.sql + /// Create a new migration with the given name, + /// using the current time as the version Add { name: String }, - /// Run all migrations + /// Run all pending migrations Run, /// List all migrations List, } -/// Create or drops database depending on your connection string. Alias: db +/// Create or drops database depending on your connection string #[derive(StructOpt, Debug)] -#[structopt(name = "Sqlx migrator")] pub enum DatabaseCommand { /// Create database in url Create, @@ -78,14 +75,17 @@ pub async fn run(cmd: Command) -> anyhow::Result<()> { MigrationCommand::Run => migration::run().await?, MigrationCommand::List => migration::list().await?, }, + Command::Database(database) => match database { DatabaseCommand::Create => db::run_create().await?, DatabaseCommand::Drop => db::run_drop().await?, }, + Command::Prepare { check: false, cargo_args, } => prepare::run(cargo_args)?, + Command::Prepare { check: true, cargo_args, diff --git a/sqlx-cli/src/migrator/mysql.rs b/sqlx-cli/src/migrator/mysql.rs index 7cb38d5c..b39e2c75 100644 --- a/sqlx-cli/src/migrator/mysql.rs +++ b/sqlx-cli/src/migrator/mysql.rs @@ -160,7 +160,7 @@ impl DatabaseMigrator for MySql { } pub struct MySqlMigration { - transaction: sqlx::Transaction>, + transaction: sqlx::Transaction<'static, sqlx::MySql, PoolConnection>, } #[async_trait] diff --git a/sqlx-cli/src/migrator/postgres.rs b/sqlx-cli/src/migrator/postgres.rs index a6278fc6..4c952656 100644 --- a/sqlx-cli/src/migrator/postgres.rs +++ b/sqlx-cli/src/migrator/postgres.rs @@ -165,7 +165,7 @@ impl DatabaseMigrator for Postgres { } pub struct PostgresMigration { - transaction: sqlx::Transaction>, + transaction: sqlx::Transaction<'static, sqlx::Postgres, PoolConnection>, } #[async_trait] diff --git a/sqlx-cli/src/migrator/sqlite.rs b/sqlx-cli/src/migrator/sqlite.rs index d226b48a..6bc6ab92 100644 --- a/sqlx-cli/src/migrator/sqlite.rs +++ b/sqlx-cli/src/migrator/sqlite.rs @@ -132,7 +132,7 @@ impl DatabaseMigrator for Sqlite { pub struct SqliteMigration { db_url: String, - // pub transaction: sqlx::Transaction>, + // pub transaction: sqlx::Transaction<'static, sqlx::Sqlite, PoolConnection>, } #[async_trait] diff --git a/src/lib.rs b/src/lib.rs index c2d83d32..4a44ec0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ pub use sqlx_core::query::{query, query_with}; pub use sqlx_core::query_as::{query_as, query_as_with}; pub use sqlx_core::query_scalar::{query_scalar, query_scalar_with}; pub use sqlx_core::row::{ColumnIndex, Row}; -// pub use sqlx_core::transaction::Transaction; +pub use sqlx_core::transaction::{Transaction, TransactionManager}; pub use sqlx_core::value::{Value, ValueRef}; #[doc(hidden)]