GithubHelp home page GithubHelp logo

musq's Introduction

Hello curious person - musq is not yet ready for use! Please check back later.

Musq

Musq is an async SQLite crate library for Rust.

Rows

Types

Types are discrete values that can be stored in a table column or appear in SQL expressions. Supported types implement one or both of the Encode and Decode traits. Encode is used to convert a Rust value into a SQLite value, and Decode is used to convert a SQLite value into a Rust value.

Built-in type support

Encode and Decode are implemented for a set of standard types.

Rust type SQLite type(s)
bool BOOLEAN
i8, i16, i32, i64 INTEGER
u8, u16, u32 INTEGER
f32, f64 REAL
&str, String, Arc<String> TEXT
&[u8], Vec<u8>, Arc<Vec<u8> BLOB
time::PrimitiveDateTime DATETIME
time::OffsetDateTime DATETIME
time::Date DATE
time::Time TIME
bstr::BString BLOB

Deriving types

You can derive Encode and Decode for a set of common custom type formats, or derive both at once with the Codec derive.

#[derive(musq::Codec)]
enum Foo {OneTwo, ThreeFour}

Enum stored as a string in snake case (the default): "one_two", "three_four".

#[derive(musq::Codec)]
#[musq(rename_all = "lower_case")]
enum Foo {OneTwo, ThreeFour}

Enum stored as a lowercase string: "onetwo", "threefour".

#[derive(musq::Codec)]
#[musq(repr = "i32")]
enum Foo {One, Two}

Enum stored as an i32: 0, 1.

#[derive(musq::Codec)]
struct Foo(i32)

A "newtype" struct stored as an i32.

#[derive(Json)]

The musq::Json derive implements Encode and Decode for any type that implements serde::Serialize and serde::Deserialize.

#[derive(musq::Json, serde::Serialize, serde::Deserialize)]
struct Foo {
    id: i32,
    name: String,
}

Handling large blobs

Musq fans out inserts into a pool of workers, so it must be able to share query arguments between threads. Say we're trying to construct an insert as follows:

query("INSERT INTO docs (txt) VALUES (?)").bind(s)

If s is a &str reference, Musq has to clone the value into an owned structure so it can control the lifetime and thread sharing. This is usually fine, but if s is large, we can avoid the copy by passing an owned String or an Arc<String> instead. The same idea holds for the reference &[u8] and its counterparts Vec<u8> and Arc<Vec<u8>>.

FIXME: Add note on efficiently querying large blobs

Development

Why?

Musq is a SQLite-focused fork of sqlx. The aims are to simplify and clean up the codebase, strip out un-needed features and complexity, add new features, improve testing and ergonomics, and support WASM.

Profiling

Run the benchmarks with profiling enabled:

cargo bench --bench benchmark -- --profile-time 10

The resulting flamegraphs are in ./targets/criterion/*/profile. At the moment, the benchmarks are only supported on Linux.

musq's People

Contributors

cortesi avatar kajojify avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.