barrel 0.1.0

A powerful schema migration building API for Rust
Documentation

Build Status Coverage Status Crates.io badge Rust docs

A schema migration building API, using Diesel as a backend and integrated query builder. Write complicated SQL schema migrations in Rust!

Example

The API was recently completely changed to potentially easily allow different database backends to be used. The current iteration of the API can be seen below. Some of the functions might not fully work yet or need tweaking. In fact, a lot of the functions haven't been properly hooked up yet 😅

extern crate barrel;

use barrel::{Schema, Table};
use barrel::generators::postgres::*;

fn main() {
    let mut sql = Schema::<PGSQL>::new();
    sql.create_table("users", |t: &mut Table<PGSQL>| {
        t.increments();
        t.string("name");
        t.integer("plushy_sharks_owned");
    });

    println!("{}", sql.exec());
    // create table "users" ("id" serial primary key, "name" varchar(255), "plushy_sharks_owned" int)
}

Connecting with a Database

Right now only Diesel (as a backend) and PGSQL (as a database) are supported. But generally, this is what it would look like to use barrel to talk directly to a database.


    // ...
    let migration = sql.exec();

    let mut connection = Connector::<DieselPGSQL>::new("postgres://<username>:<password>@<server>/<database>");
    connection.batch_exec(&migration);

If you have feedback regarding the API or things you would want barrel to do, please open an issue. And documentation PR's are always welcome 💚