ankhdb 2.0.0+1
ankhdb: ^2.0.0+1 copied to clipboard
Official AnkhDB Client SDK for Dart and Flutter. Real-time Multi-tenant BaaS.
ankhdb #
The official Dart & Flutter SDK for AnkhDB — a self-hosted, multi-tenant Backend-as-a-Service with Auth, Database, Storage, and Edge Functions.
Installation #
Add ankhdb to your pubspec.yaml:
dependencies:
ankhdb: ^2.0.0
Or run:
dart pub add ankhdb
Quick Start #
Find your Project ID and API Key in the AnkhDB Dashboard → Settings.
import 'package:ankhdb/ankhdb.dart';
final db = AnkhDB('YOUR_PROJECT_ID', 'YOUR_API_KEY');
// Self-hosted / local override:
// final db = AnkhDB('YOUR_PROJECT_ID', 'YOUR_API_KEY', serverUrl: 'http://localhost:5000');
Authentication #
Manage your app's end-users. Enable Require Email Verification in the dashboard to gate logins behind email confirmation.
// Register a new user
var res = await db.register('user@example.com', 'securepassword');
// res['token'] is set automatically (or absent if email verification is required)
// Login
await db.login('user@example.com', 'securepassword');
// Check current session
var session = await db.getSession();
// Logout (clears local token)
db.logout();
Database #
Schema-free NoSQL collections with optional Row-Level Security (RLS) policies.
final posts = db.from('posts');
// Insert
var doc = await posts.insert({'title': 'Hello AnkhDB', 'author': 'Alice'});
// Read all
var all = await posts.select();
// Read one
var one = await posts.get(doc['id']);
// Update
await posts.update(doc['id'], {'title': 'Updated Title'});
// Delete
await posts.delete(doc['id']);
Storage #
Upload and manage files up to 50 MB per file.
// Upload from bytes (e.g. picked with image_picker)
final bytes = await file.readAsBytes();
final uploaded = await db.storage.upload(bytes, 'photo.jpg', mimeType: 'image/jpeg');
print(uploaded['url']); // Public URL
// List all files
final files = await db.storage.list();
// Get file metadata
final meta = await db.storage.getFile(uploaded['id']);
// Delete
await db.storage.delete(uploaded['id']);
Edge Functions #
Invoke serverless JavaScript functions you write in the AnkhDB Dashboard.
// Invoke a function named "greet"
final res = await db.functions.invoke('greet', payload: {'name': 'Alice'});
print(res['result']); // Whatever the function set on `result`
Example function code (written in the dashboard):
result = { greeting: `Hello, ${payload.name}!` };
API Reference #
| Method | Description |
|---|---|
AnkhDB(projectId, apiKey, {serverUrl?, token?}) |
Create a client. |
db.register(email, password) |
Register a new end-user. |
db.login(email, password) |
Login and auto-store JWT. |
db.logout() |
Clear the local token (synchronous). |
db.getSession() |
Verify token, get user info. |
db.from(collection) |
Get a query builder for a collection. |
db.getCollections() |
List all collections. |
db.storage.upload(bytes, filename, {mimeType?}) |
Upload a file from bytes. |
db.storage.list() |
List all uploaded files. |
db.storage.getFile(id) |
Get file metadata + URL. |
db.storage.delete(id) |
Delete a file. |
db.functions.invoke(name, {payload?}) |
Invoke an edge function. |
Additional Information #
Visit the AnkhDB Dashboard to manage your projects, auth users, storage files, and edge functions.
License #
MIT © KemetSoft