SQLite

Create a SQLite database

rusqlite-badge cat-database-badge

Use the rusqlite crate to open SQLite databases. See crate for compiling on Windows.

Connection::open will create the database if it doesn't already exist.

extern crate rusqlite;

use rusqlite::{Connection, Result};

fn main() -> Result<()> {
    let conn = Connection::open("cats.db")?;

    conn.execute(
        "create table if not exists cat_colors (
             id integer primary key,
             name text not null
         )",
        &[],
    )?;
    conn.execute(
        "create table if not exists cats (
             id integer primary key,
             name text not null,
             date_of_birth datetime,
             color_id integer not null references cat_colors(id)
         )",
        &[],
    )?;

    Ok(())
}