1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
//! 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 //! //! ```notest //! let mut connection = Connector::<DieselPGSQL>::new("postgres://<username>:<password>@<server>/<database>"); //! connection.batch_exec(&migration); //! ``` //! //! Pull-Requests with more/ better documentation welcome 💚 #[cfg(feature = "default")] extern crate diesel; pub mod connectors; pub mod table; pub mod schema; pub mod generators; /* Conveniently expose core structures */ pub use table::Table; pub use schema::Schema; pub use connectors::Connector; /* Test module */ mod test;