Create SQlite database

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    database with rusqlite

    use rusqlite::{Connection, Result};
    use rusqlite::NO_PARAMS;
    
    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 unique
        )",
        NO_PARAMS,
      )?;
      conn.execute(
        "create table if not exists cats (
        id integer primary key,
        name text not null,
        color_id integer not null references cat_colors(id)
        )",
        NO_PARAMS,
      )?;
      Ok(())
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.