ic-dbms-canister 0.9.0

A framework to build Database canisters on the Internet Computer using DBMS, by just providing the schema.
Documentation

ic-dbms-canister

logo

license-mit repo-stars downloads latest-version conventional-commits

ci coveralls docs

A framework to build database canisters on the Internet Computer, powered by the wasm-dbms engine.

Define your data tables using Rust structs, derive the Table and DbmsCanister traits, and get a fully functional database canister with CRUD operations, transactions, and ACL-based access control.

Usage

Add dependencies

[dependencies]
candid = { version = "0.10", features = ["value"] }
ic-cdk = "0.19"
ic-dbms-api = "0.6"
ic-dbms-canister = "0.6"
serde = "1"

Define tables

use candid::CandidType;
use ic_dbms_api::prelude::{Nullable, Text, Uint32, Uint64};
use ic_dbms_canister::prelude::{DbmsCanister, Table};
use serde::Deserialize;

#[derive(Debug, Table, CandidType, Deserialize, Clone, PartialEq, Eq)]
#[table = "users"]
pub struct User {
    #[primary_key]
    id: Uint64,
    name: Text,
    email: Text,
    age: Nullable<Uint32>,
}

#[derive(Debug, Table, CandidType, Deserialize, Clone, PartialEq, Eq)]
#[table = "posts"]
pub struct Post {
    #[primary_key]
    id: Uint32,
    title: Text,
    content: Text,
    #[foreign_key(entity = "User", table = "users", column = "id")]
    author: Uint32,
}

#[derive(DbmsCanister)]
#[tables(User = "users", Post = "posts")]
pub struct IcDbmsCanisterGenerator;

Generated Candid API

service : (IcDbmsCanisterArgs) -> {
  acl_add_principal : (principal) -> (Result);
  acl_allowed_principals : () -> (vec principal) query;
  acl_remove_principal : (principal) -> (Result);
  begin_transaction : () -> (nat);
  commit : (nat) -> (Result);
  delete_posts : (DeleteBehavior, opt Filter_1, opt nat) -> (Result_1);
  delete_users : (DeleteBehavior, opt Filter_1, opt nat) -> (Result_1);
  insert_posts : (PostInsertRequest, opt nat) -> (Result);
  insert_users : (UserInsertRequest, opt nat) -> (Result);
  rollback : (nat) -> (Result);
  select_posts : (Query, opt nat) -> (Result_2) query;
  select_users : (Query_1, opt nat) -> (Result_3) query;
  update_posts : (PostUpdateRequest, opt nat) -> (Result_1);
  update_users : (UserUpdateRequest, opt nat) -> (Result_1);
}

Interacting with the Canister

See the ic-dbms-client crate for a client library to interact with the canister from other canisters, frontend applications, or CLI tools.

Documentation

Read the full documentation at https://wasm-dbms.cc/ic/

License

This project is licensed under the MIT License. See the LICENSE file for details.