项目作者: swissChili

项目描述 :
A simple relational DB
高级语言: Rust
项目地址: git://github.com/swissChili/kiln.git
创建时间: 2019-02-24T21:47:49Z
项目社区:https://github.com/swissChili/kiln

开源协议:

下载


Kiln v0.2



Kiln is a relational database implemented in Rust. Unlike databases like PostgreSQL and SQLite, Kiln does not operate on a client-server model. Instead, it is a stand-alone library that allows it to be used with zero dependencies.

This is a very early version of the database. So far the only thing done is the format the database stores tables.

A high level guide is available that provides an introduction to Kiln.

Features implemented so far

  • Creating databases
  • Creating and accessing existing tables
    • Accessing rows from tables
      • By row ID
      • By value (eg: find all rows where foo = bar)
    • Parse specfiles for type safe columns
  • Accessing rows
    • Getting columns from rows
    • Setting columns in rows

Roadmap

  • Implement O(1) joining (Easier said than done)
  • Make this all thread-safe with async support (futures maybe?)

Usage

Here is a simple example of working with one simple table. The structure of the queries is very different from how it would be accomplished in a tradition SQL database. This unique structure makes it possible to easily interact with the database using expressive, declarative Rust code.

  1. #[macro_use]
  2. extern crate kiln;
  3. fn main() {
  4. // Create a new database in the `data` dir
  5. let db = kiln::Db::new("data").expect("Failed to create or access db");
  6. // Create or access a table "users" with col types int and string
  7. let users = db.table("users", table!{
  8. age: i32,
  9. name: str
  10. }).expect("Table with same name exists with different spec");
  11. // Insert a row into the users table
  12. let mut bob = users.insert(row!{
  13. name: "Bob",
  14. age: 24
  15. }).expect("Could not insert row");
  16. users.insert(row!{
  17. name: "Jeff",
  18. age: 24
  19. }).expect("Failed to insert");
  20. println!("Bob is {} years old", bob["age"].i32().unwrap());
  21. //=> Bob is 24 years old
  22. bob.set("age", 42);
  23. println!("Bob is now {} years old", bob["age"].i32().unwrap());
  24. for user in users.get("age", 24) {
  25. println!("24 year old named {}", user["name"].string().unwrap());
  26. }
  27. //=> 24 year old named Jeff
  28. }