Coder Social home page Coder Social logo

sqlx-crud's Introduction

sqlx-crud

sqlx-crud is an extension to SQLx to derive Create, Read, Update, and Delete (CRUD) methods for a struct representing a table in a sqlx database.

use sqlx::FromRow;
use sqlx_crud::SqlxCrud;

#[derive(Debug, FromRow, SqlxCrud)]
struct User {
    user_id: i32,
    name: String,
}

if let Some(user) = User::by_id(&pool, 42) {
    println!("Found user user_id=42: {:?}", user);
}

Notable Features

  • Single Derive Macro for Structs

  • Methods to Create, Read, Update, and Delete Records

  • Primary Key and Table Name Inference

  • Table Metadata for Reuse

  • Internal and External Database ID Assignment

This removes much of the common, repetitive code needed when dealing with the typical CRUD operations.

sqlx-crud strives to do a few, narrowly defined things well in an effort to reduce 80% of the redundant code you might write for a database application when operating on a single table at a time. It provides mechanisms: Schema and Crud, to access and reuse the generated id, column, and query metadata. This can help with writing more complex queries outside of the single table CRUD paradigm, but its primary use case is for CRUD.

Installation

Installing sqlx-crud is similar to installing SQLx.

# Cargo.toml
[dependencies]
sqlx-crud = { version = "0", features = ["runtime-tokio-rustls"] }

See the documentation for full usage instructions.

Features

sqlx-crud uses the same features as SQLx runtime-* flags and are required because of the dependency on SQLx.

Examples

You can find real-world examples under the examples directory.

Source code

Source code for sqlx-crud is available at https://www.github.com/treydempsey/sqlx-crud.

Tests

The doctests depend on SQLx and it's runtime-tokio-rustls and sqlite features.

The tests can be run with:

$ cargo test

Documentation

Documentation is hosted at sqlx-crud docs.

Roadmap

sqlx-crud does most of what I need it to do, however while packaging it for release to others I realized there are several improvements that could be made. Planned updates and major achievements are listed in MILESTONES.

License

sqlx-crud is licensed under the MIT license (see: LICENSE).

sqlx-crud's People

Contributors

treydempsey avatar yyykt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.