Can I use diesel with both MySQL and SQLite?


#1

I need to pour data in MySQL into SQLite. Is it possible to do this with diesel? What I has found is that it seems that the diesel codegen and toolchain presume that it is either one of MySQL, SQLite and PG.


#2

You can use diesel with as many backends as are available. Specify the dependency like diesel = { version = "0.16", features = ["mysql", "sqlite"] } and you’ll have access to diesel::sqlite::SqliteConnection as well as diesel::mysql::MysqlConnection.


#3

What about infer_schema!? The compiler stops when trying to reflect my sqlite schema.


#4
MacBook-of-Jackal:license-bureau jackalcooper$ cargo run --bin create_partner
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling diesel_infer_schema v0.16.0
error[E0599]: no method named `load` found for type `diesel::query_builder::SelectStatement<information_schema::information_schema::key_column_usage::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::key_column_usage::columns::column_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::And<diesel::expression::operators::And<diesel::expression::array_comparison::In<information_schema::information_schema::key_column_usage::columns::constraint_name, diesel::expression::array_comparison::Subselect<diesel::query_builder::SelectStatement<information_schema::information_schema::table_constraints::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::table_constraints::columns::constraint_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::Eq<information_schema::information_schema::table_constraints::columns::constraint_type, diesel::expression::bound::Bound<diesel::types::Text, &str>>>>, diesel::types::Text>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_name, diesel::expression::bound::Bound<diesel::types::Text, &std::string::String>>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_schema, diesel::expression::bound::Bound<diesel::types::Text, std::string::String>>>>, diesel::query_builder::order_clause::OrderClause<information_schema::information_schema::key_column_usage::columns::ordinal_position>>` in the current scope
   --> /Users/jackalcooper/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel_infer_schema-0.16.0/src/information_schema.rs:156:10
    |
156 |         .load(conn)
    |          ^^^^
    |
    = note: the method `load` exists but the following trait bounds were not satisfied:
            `diesel::query_builder::SelectStatement<information_schema::information_schema::key_column_usage::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::key_column_usage::columns::column_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::And<diesel::expression::operators::And<diesel::expression::array_comparison::In<information_schema::information_schema::key_column_usage::columns::constraint_name, diesel::expression::array_comparison::Subselect<diesel::query_builder::SelectStatement<information_schema::information_schema::table_constraints::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::table_constraints::columns::constraint_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::Eq<information_schema::information_schema::table_constraints::columns::constraint_type, diesel::expression::bound::Bound<diesel::types::Text, &str>>>>, diesel::types::Text>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_name, diesel::expression::bound::Bound<diesel::types::Text, &std::string::String>>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_schema, diesel::expression::bound::Bound<diesel::types::Text, std::string::String>>>>, diesel::query_builder::order_clause::OrderClause<information_schema::information_schema::key_column_usage::columns::ordinal_position>> : diesel::LoadDsl<_>`
            `&diesel::query_builder::SelectStatement<information_schema::information_schema::key_column_usage::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::key_column_usage::columns::column_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::And<diesel::expression::operators::And<diesel::expression::array_comparison::In<information_schema::information_schema::key_column_usage::columns::constraint_name, diesel::expression::array_comparison::Subselect<diesel::query_builder::SelectStatement<information_schema::information_schema::table_constraints::table,diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::table_constraints::columns::constraint_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::Eq<information_schema::information_schema::table_constraints::columns::constraint_type, diesel::expression::bound::Bound<diesel::types::Text, &str>>>>, diesel::types::Text>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_name, diesel::expression::bound::Bound<diesel::types::Text, &std::string::String>>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_schema, diesel::expression::bound::Bound<diesel::types::Text, std::string::String>>>>, diesel::query_builder::order_clause::OrderClause<information_schema::information_schema::key_column_usage::columns::ordinal_position>> : diesel::LoadDsl<_>`
            `&mut diesel::query_builder::SelectStatement<information_schema::information_schema::key_column_usage::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::key_column_usage::columns::column_name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::And<diesel::expression::operators::And<diesel::expression::array_comparison::In<information_schema::information_schema::key_column_usage::columns::constraint_name, diesel::expression::array_comparison::Subselect<diesel::query_builder::SelectStatement<information_schema::information_schema::table_constraints::table, diesel::query_builder::select_clause::SelectClause<information_schema::information_schema::table_constraints::columns::constraint_name>,diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::Eq<information_schema::information_schema::table_constraints::columns::constraint_type, diesel::expression::bound::Bound<diesel::types::Text, &str>>>>, diesel::types::Text>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_name, diesel::expression::bound::Bound<diesel::types::Text, &std::string::String>>>, diesel::expression::operators::Eq<information_schema::information_schema::key_column_usage::columns::table_schema, diesel::expression::bound::Bound<diesel::types::Text, std::string::String>>>>, diesel::query_builder::order_clause::OrderClause<information_schema::information_schema::key_column_usage::columns::ordinal_position>> : diesel::LoadDsl<_>`

error: aborting due to previous error

error: Could not compile `diesel_infer_schema`.

#5

while diesel print-schema print the right schema when given right file path as database url


#6
Caused by:
  process didn't exit successfully: `rustc --crate-name diesel_infer_schema /Users/jackalcooper/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel_infer_schema-0.16.0/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg feature="diesel" --cfg feature="mysql" --cfg feature="sqlite"--cfg feature="uses_information_schema" -C metadata=256f7be3b5b79b6e -C extra-filename=-256f7be3b5b79b6e --out-dir /Users/jackalcooper/rust/license-bureau/target/debug/deps -L dependency=/Users/jackalcooper/rust/license-bureau/target/debug/deps --extern diesel=/Users/jackalcooper/rust/license-bureau/target/debug/deps/libdiesel-a4652098ef005d57.rlib --cap-lints allow -L native=/usr/local/Cellar/mysql/5.7.19/lib` (exit code: 101)