ORM for ScyllaDb and Cassandra

Related tags

Database scylla_orm
Overview

ScyllaDb/Cassandra Object-Relation Mapper

Latest Version Build Status

Features

This library contains several crates with the following features:

  • Automatic map tables to Rust structs: scylla_orm_table_to_struct. See Usage. See the generated dir for the generated code.
  • Compile time checked queries: scylla_orm_macro (scylla_orm_macro::query). See Usage.
  • Plugin derive macro to generate business logic: scylla_orm_macro (scylla_orm_macro::mirror)
  • Automatic JSON mapping. When there is a column with type text, you can implement the Transformer trait and map it to a type that implements serde::Serialize and serde::Deserialize
  • All queries are executed as a prepared statement
  • Support for Materialized Views (and mapping between the base table if the columns are the same)

Not all types are supported yet due to https://github.com/scylladb/scylla-rust-driver/issues/104

Query types

Depending on a query, a certain query type can be derived. These can be found here. These are the commonly used query types:

  • SelectMultiple: Can be used as an iterator to iterate over the rows
  • SelectUnique: Selects an optional unique row by full primary key
  • SelectUniqueExpect: Same as SelectUnique, but fails if the row doesn't exist
  • SelectUniqueExpect with Count as entity type: has the special select_count method for queries like "select count(*) from ..."

There are also structs for CRUD operations.

Usage

Automatic map tables to Rust

You can see an example on how to generate Rust structs in the example dir.

  • In the build.rs file the Transformer trait is implemented and used for json mapping
  • In the generated dir you can see the generated structs

How to implement it yourself (step-by-step guide how to mimic the example crate):

  • Add a build-dependency: scylla_orm_table_to_struct = "0.1"
  • Create a build.rs file
  • Optionally implement the Tranformer trait (or use DefaultTransformer)
  • Call scylla_orm_table_to_struct::generate
  • Build the project

An example of the structure of the generated code for table 'child' is:

  • Child: a struct with owned values. Can be converted to ChildRef, PrimaryKey and PrimaryKeyRef
  • ChildRef: a struct where the values are all borrowed. This struct can perform insertions. Can be converted to Child, PrimaryKey and PrimaryKeyRef
  • PrimaryKey: a struct which holds the owned values of the primary key fields of Child. Can be converted to PrimaryKeyRef.
  • PrimaryKeyRef: a struct where the values are all borrowed. This struct can perform updates, deletions and selects. Can be converted to PrimaryKey
  • UpdatableColumn: an enum which holds the enum variants with owned values of columns that can be updated. Can be converted to UpdatableColumnRef.
  • UpdatableColumnRef: an enum where the values are all borrowed. This is used by PrimaryKeyRef for updates. Can be converted to UpdatableColumn.

Macros

Crate scylla_orm_macro holds several macros that can be used to ensure compile/type checked queries. Examples on how this can be used can be found in lib.rs, method qmd.

How to implement it yourself:

  • Add dependency: scylla_orm_macro = "0.1"
  • The query macro returns the correct query type for the given query
  • The query_base_table macro transforms a select query to the materialized view table, to a select query of the base table
  • mirror and primary_key can be used for other derive macros
You might also like...
Rust High Performance compile-time ORM(RBSON based)
Rust High Performance compile-time ORM(RBSON based)

WebSite | 简体中文 | Showcase | 案例 A highly Performant,Safe,Dynamic SQL(Compile time) ORM framework written in Rust, inspired by Mybatis and MybatisPlus.

Bind the Prisma ORM query engine to any programming language you like ❤️

Prisma Query Engine C API Bind the Prisma ORM query engine to any programming language you like ❤️ Features Rust bindings for the C API Static link li

Bind the Prisma ORM query engine to any programming language you like ❤️

Prisma Query Engine C API Bind the Prisma ORM query engine to any programming language you like ❤️ Features Rust bindings for the C API Static link li

Skybase is an extremely fast, secure and reliable real-time NoSQL database with automated snapshots and SSL
Skybase is an extremely fast, secure and reliable real-time NoSQL database with automated snapshots and SSL

Skybase The next-generation NoSQL database What is Skybase? Skybase (or SkybaseDB/SDB) is an effort to provide the best of key/value stores, document

Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.
Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.

Description Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLit

Skytable is an extremely fast, secure and reliable real-time NoSQL database with automated snapshots and TLS
Skytable is an extremely fast, secure and reliable real-time NoSQL database with automated snapshots and TLS

Skytable is an effort to provide the best of key/value stores, document stores and columnar databases, that is, simplicity, flexibility and queryability at scale. The name 'Skytable' exemplifies our vision to create a database that has limitless possibilities. Skytable was previously known as TerrabaseDB (and then Skybase) and is also nicknamed "STable", "Sky" and "SDB" by the community.

asynchronous and synchronous interfaces and persistence implementations for your OOD architecture

OOD Persistence Asynchronous and synchronous interfaces and persistence implementations for your OOD architecture Installation Add ood_persistence = {

rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

Efficient and fast querying and parsing of GTDB's data

xgt xgt is a Rust tool that enables efficient querying and parsing of the GTDB database. xgt consists of a collection of commands mirroring the GTDB A

Comments
  • Upload to crates

    Upload to crates

    This can be done if the following issues are closed:

    • https://github.com/scylladb/scylla-rust-driver/pull/261
    • https://github.com/scylladb/scylla-rust-driver/pull/297
    • https://github.com/scylladb/scylla-rust-driver/pull/308
    • https://github.com/scylladb/scylla-rust-driver/pull/309
    • https://github.com/scylladb/scylla-rust-driver/issues/332

    When above issues are closed:

    1. Check that https://github.com/Jasperav/scylla-rust-driver is the same as the original driver
    2. Remove https://github.com/Jasperav/scylla-rust-driver
    3. Update to the crates scylla rust driver in this crate
    4. Push to crates
    5. Add a reference to this crate in the scylla rust driver repo
    opened by Jasperav 1
  • Implement TIMESTAMP/TIMEOUT for inserts

    Implement TIMESTAMP/TIMEOUT for inserts

    The ORM does not support TIMESTAMP and TIMEOUTs for inserts yet: https://docs.scylladb.com/getting-started/dml/#insert-statement.

    This can be implemented by following these steps:

    1. Add the new method name in query_ident.rs. The query ident mod can be used by other users to interact with always up to date methods, so they never have to type the method names themselves and run into run time errors
    2. Add the new insert method somewhere in write_struct.rs, after the insert method (see line 177).
    3. Add a test in lib.rs. I want each new change to be tested.

    To see the changes of the generated code easily:

    1. Change a line somewhere in build.rs. (there is no cargo:rerun-if-changed). This should trigger re-generation of the structs. The structs are in version control, so it should be easy to see what has been changed.
    2. Run the test in lib.rs.
    opened by Jasperav 0
Releases(0.1.0)
Owner
null
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

CDRS CDRS is looking for maintainers CDRS is Apache Cassandra driver written in pure Rust. ?? Looking for an async version? async-std https://github.c

Alex Pikalov 338 Jan 1, 2023
Cassandra (CQL) driver for Rust, using the DataStax C/C++ driver under the covers.

cassandra-cpp This is a maintained Rust project that exposes the DataStax cpp driver at https://github.com/datastax/cpp-driver/ in a somewhat-sane cra

null 93 Jan 7, 2023
High-level async Cassandra client written in 100% Rust.

CDRS tokio CDRS is production-ready Apache Cassandra driver written in pure Rust. Focuses on providing high level of configurability to suit most use

Kamil Rojewski 73 Dec 26, 2022
A safe, extensible ORM and Query Builder for Rust

A safe, extensible ORM and Query Builder for Rust API Documentation: latest release – master branch Homepage Diesel gets rid of the boilerplate for da

Diesel 9.7k Jan 3, 2023
Diesel - A safe, extensible ORM and Query Builder for Rust

A safe, extensible ORM and Query Builder for Rust API Documentation: latest release – master branch Homepage Diesel gets rid of the boilerplate for da

Takayuki Maeda 0 Aug 31, 2020
CRUD system of book-management with ORM and JWT for educational purposes.

Book management English | 中文 Required Rust MySQL 5.7 Usage Execute init.sql to create tables. Set environment variable DATABASE_URL and JWT_SECRET in

null 32 Dec 28, 2022
Diesel - ORM and Query Builder for Rust

A safe, extensible ORM and Query Builder for Rust API Documentation: latest release – master branch Homepage Diesel gets rid of the boilerplate for da

Diesel 9.7k Jan 6, 2023
an orm for rust

rustorm Rustorm Rustorm is an SQL-centered ORM with focus on ease of use on conversion of database types to their appropriate rust type. Selecting rec

Jovansonlee Cesar 236 Dec 19, 2022
🐚 An async & dynamic ORM for Rust

SeaORM ?? An async & dynamic ORM for Rust SeaORM SeaORM is a relational ORM to help you build web services in Rust with the familiarity of dynamic lan

SeaQL 3.5k Jan 6, 2023
Ormlite - An ORM in Rust for developers that love SQL.

ormlite ormlite is an ORM in Rust for developers that love SQL. It provides the following, while staying close to SQL, both in syntax and performance:

Kurt Wolf 28 Jan 1, 2023