/Rusqdrive

-

Primary LanguageRustMIT LicenseMIT

Rusqdrive

dependency status


Description

Implement:

  • CREATE TABLE

  • READ COUNT

  • READ ALL

  • INSERT ONE

  • UPDATE ONE

  • DELETE ONE

  • Pure Rust: Written in pure Rust using zero unsafe code.

Techs

  • rusqlite: Ergonomic bindings to SQLite for Rust (GitHub)
  • syn: A parsing library for parsing a stream of Rust tokens into a syntax tree of Rust source code. (GitHub)
  • quote: Provides the quote! macro for turning Rust syntax tree data structures into tokens of source code. (GitHub)
  • proc-macro2: A wrapper around the procedural macro API of the compiler's proc_macro crate. (GitHub)

Usage

1. Imports

use rusqdrive::prelude::*;

2. Add #[tablename = "tablename"] and Rusdrive derive

#[tablename = "tablename"]
#[derive(Rusqdrive)]

3. Add #[rusqdrive(not_null = false, unique = false)] attribute in all fields except id

#[rusqdrive(not_null = [true | false], unique = [true | false])]

4. Example - Look at examples/usercrud

#[tablename = "tablename"]
#[derive(Debug, Default, Rusqdrive)]
pub struct User {
    pub id: Option<i32>,
    #[rusqdrive(not_null = false, unique = false)]
    pub name: Option<String>,
    #[rusqdrive(not_null = false, unique = false)]
    pub age: f64,
    #[rusqdrive(not_null = false, unique = false)]
    pub alive: bool,
}

5.Cargo deny - Cargo plugin for linting your dependencies

make cargo-deny

cargo-deny status output

6. Repos that helped me with derive code

  1. GetSet
  2. Diesel
  3. Oxidizer
  4. Rocket
  5. Validator
  6. Sqlx

7. Run example

make