All Projects → tokio-rs → Rdbc

tokio-rs / Rdbc

Licence: apache-2.0
Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Rdbc

Ebean
Ebean ORM
Stars: ✭ 1,172 (+257.32%)
Mutual labels:  database, mysql, sqlite, postgres
East
node.js database migration tool
Stars: ✭ 53 (-83.84%)
Mutual labels:  database, mysql, sqlite, postgres
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+2251.22%)
Mutual labels:  database, mysql, sqlite, postgres
Qtl
A friendly and lightweight C++ database library for MySQL, PostgreSQL, SQLite and ODBC.
Stars: ✭ 92 (-71.95%)
Mutual labels:  odbc, database, mysql, sqlite
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+543.9%)
Mutual labels:  database, mysql, sqlite, postgres
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+286.28%)
Mutual labels:  database, mysql, sqlite, postgres
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+200%)
Mutual labels:  database, mysql, sqlite, postgres
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+5439.02%)
Mutual labels:  database, mysql, postgres, sqlite
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+605.79%)
Mutual labels:  database, mysql, sqlite, postgres
Wetland
A Node.js ORM, mapping-based. Works with MySQL, PostgreSQL, SQLite and more.
Stars: ✭ 261 (-20.43%)
Mutual labels:  database, mysql, sqlite, postgres
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+836.28%)
Mutual labels:  mysql, sqlite, postgres
Node Orm2
Object Relational Mapping
Stars: ✭ 3,063 (+833.84%)
Mutual labels:  database, mysql, sqlite
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+763.41%)
Mutual labels:  database, mysql, sqlite
Fluentmigrator
Fluent migrations framework for .NET
Stars: ✭ 2,636 (+703.66%)
Mutual labels:  database, mysql, postgres
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+1081.1%)
Mutual labels:  database, mysql, sqlite
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+785.37%)
Mutual labels:  database, mysql, sqlite
Architect
A set of tools which enhances ORMs written in Python with more features
Stars: ✭ 320 (-2.44%)
Mutual labels:  database, mysql, postgres
Eosio sql plugin
EOSIO sql database plugin
Stars: ✭ 21 (-93.6%)
Mutual labels:  odbc, mysql, sqlite
Zabbixdba
Zabbix Database Monitoring Service (Oracle, Pg, MySQL, MS SQL, DB2, etc.)
Stars: ✭ 68 (-79.27%)
Mutual labels:  odbc, database, mysql
Endb
Key-value storage for multiple databases. Supports MongoDB, MySQL, Postgres, Redis, and SQLite.
Stars: ✭ 208 (-36.59%)
Mutual labels:  database, mysql, sqlite

Rust DataBase Connectivity (RDBC)

License Docs Version

Love them or hate them, the ODBC and JDBC standards have made it easy to use a wide range of desktop and server products with many different databases thanks to the availability of database drivers implementing these standards.

This project provides a Rust equivalent API as well as reference implementations (drivers) for Postgres, MySQL, and SQLite. There is also an RDBC-ODBC driver being developed, that will allow ODBC drivers to be called via the RDBC API, so that it is also possible to connect to databases that do not yet have Rust drivers available.

Note that the provided RDBC drivers are just wrappers around existing database driver crates and this project is not attempting to build new drivers from scratch but rather make it possible to leverage existing drivers through a common API.

Why do we need this when we have Diesel?

This is filling a different need. I love the Diesel approach for building applications but if you are building a generic SQL tool, a business intelligence tool, or a distributed query engine, there is a need to connect to different databases and execute arbitrary SQL. This is where we need a standard API and available drivers.

RDBC API PoC

Note that the design of the RDBC API is intentionally modeled directly after ODBC and JDBC (except that indices are 0-based rather than 1-based) and that is likely to change to make this more idiomatic for Rust.

There is currently no async support and that will be addressed soon.

There are also design flaws with the current design, such as the limitation of only being able to create one prepared statement per connection.

Work is in progress of the next iteration of this project and there will definitely be breaking changes.

/// Represents database driver that can be shared between threads, and can therefore implement
/// a connection pool
pub trait Driver: Sync + Send {
    /// Create a connection to the database. Note that connections are intended to be used
    /// in a single thread since most database connections are not thread-safe
    fn connect(&self, url: &str) -> Result<Box<dyn Connection>>;
}

/// Represents a connection to a database
pub trait Connection {
    /// Create a statement for execution
    fn create(&mut self, sql: &str) -> Result<Box<dyn Statement + '_>>;

    /// Create a prepared statement for execution
    fn prepare(&mut self, sql: &str) -> Result<Box<dyn Statement + '_>>;
}

/// Represents an executable statement
pub trait Statement {
    /// Execute a query that is expected to return a result set, such as a `SELECT` statement
    fn execute_query(&mut self, params: &[Value]) -> Result<Box<dyn ResultSet + '_>>;

    /// Execute a query that is expected to update some rows.
    fn execute_update(&mut self, params: &[Value]) -> Result<u64>;
}

/// Result set from executing a query against a statement
pub trait ResultSet {
    /// get meta data about this result set
    fn meta_data(&self) -> Result<Box<dyn ResultSetMetaData>>;

    /// Move the cursor to the next available row if one exists and return true if it does
    fn next(&mut self) -> bool;

    fn get_i8(&self, i: u64) -> Result<Option<i8>>;
    fn get_i16(&self, i: u64) -> Result<Option<i16>>;
    fn get_i32(&self, i: u64) -> Result<Option<i32>>;
    fn get_i64(&self, i: u64) -> Result<Option<i64>>;
    fn get_f32(&self, i: u64) -> Result<Option<f32>>;
    fn get_f64(&self, i: u64) -> Result<Option<f64>>;
    fn get_string(&self, i: u64) -> Result<Option<String>>;
    fn get_bytes(&self, i: u64) -> Result<Option<Vec<u8>>>;

    // NOTE that only a subset of data types are supported so far in this PoC
    // and accessors need to be added for other types such as date and time
}

/// Meta data for result set
pub trait ResultSetMetaData {
    fn num_columns(&self) -> u64;
    fn column_name(&self, i: usize) -> String;
    fn column_type(&self, i: usize) -> DataType;
}

Examples

Execute a Query

let driver: Arc<dyn rdbc::Driver> = Arc::new(PostgresDriver::new());
let mut conn = driver.connect("postgres://user:[email protected]:5433")?;
let mut stmt = conn.prepare("SELECT a FROM test")?;
let mut rs = stmt.execute_query(&vec![])?;
while rs.next() {
  println!("{:?}", rs.get_string(1)?);
}

Current Status

This is just an experimental PoC and is not currently suitable for anything. However, I do intend to make it useful pretty quickly and I am tracking issues here.

The immediate priorities though are:

  • [x] Announce project and get initial feedback
  • [x] Support parameterized queries
  • [x] Support prepared statements
  • [x] Implement simple SQL console CLI
  • [ ] Design for async
  • [ ] Support connection pooling
  • [ ] Implement comprehensive unit and integration tests
  • [ ] Add support for more data types
  • [ ] Implement RDBC-ODBC bridge
  • [ ] Implement dynamic loading of drivers at runtime

License

RDBC is licensed under Apache Licence, Version 2.0.

Contributing

Please refer to the contributors guide before contributing to this project and for information on building and testing locally.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].