Crate barrel [−] [src]
Powerful schema builder API in Rust, using Diesel in the backend.
Barrel has two primary models, the schema and the table. A schema is built with a variety of hooks that can be executed on tables, using static callbacks.
use barrel::{Schema, Table}; use barrel::generators::postgres::*; // Pick the backend of your choice here let mut sql = Schema::<PGSQL>::new(); sql.create_table("users", |t: &mut Table<PGSQL>| { t.increments(); t.string("username"); t.integer("plushy_sharks_owned"); }); println!("{}", sql.exec());
The above code, for example, will create a new table in the "public" schema, called "users"
and then execute the table hook on it when invoking schema.exec()
. The hook creates an
auto-incrementing primary intex. By default the name "id" is assumed.
Barrel is designed to give you ease of use as well as power over how you write your migrations and SQL schemas.
Connect to Database
Barrel uses the Diesel connections and currently only supports postgresql databases. To
create a connection, use the Connector
module
let mut connection = Connector::<DieselPGSQL>::new("postgres://<username>:<password>@<server>/<database>");
connection.batch_exec(&migration);
Pull-Requests with more/ better documentation welcome 💚
Reexports
pub use table::Table; |
pub use schema::Schema; |
pub use connectors::Connector; |
Modules
connectors |
Database connection backends |
generators |
AN SQL string generator module |
schema |
Schema builder API |
table |
Table builder API module |