Swift

Swift client for ChronDB, auto-generated from the Rust SDK via UniFFIarrow-up-right.

Requirements

  • Swift 5.5+

  • macOS 12+ or Linux

Installation

Add via Swift Package Manager:

.package(url: "https://github.com/avelino/chrondb-swift", from: "0.1.0")

Quick Start

import ChronDB

// Single path (preferred)
let db = try ChronDB.openPath(dbPath: "./mydb")

// Save a document
try db.put(id: "user:1", jsonDoc: #"{"name": "Alice", "age": 30}"#, branch: nil)

// Retrieve it
let doc = try db.get(id: "user:1", branch: nil)
print(doc) // {"name":"Alice","age":30}

Legacy API (deprecated): ChronDB.open(dataPath:indexPath:) still works but is deprecated. Use openPath instead.

API Reference

ChronDB.openPath(dbPath:) throws -> ChronDB

Opens a database connection using a single directory path. Data and index are stored in subdirectories automatically.

ChronDB.open(dataPath:indexPath:) throws -> ChronDB (deprecated)

Deprecated. Use openPath instead. This method still works but will be removed in a future release.

ChronDB.openWithIdleTimeout(dataPath:indexPath:idleTimeoutSecs:) throws -> ChronDB

Opens a database with idle timeout.

Operations

Method
Description

put(id:jsonDoc:branch:)

Save a document

get(id:branch:)

Get a document by ID

delete(id:branch:)

Delete a document

listByPrefix(prefix:branch:)

List by ID prefix

listByTable(table:branch:)

List by table

history(id:branch:)

Get change history

query(queryJson:branch:)

Execute a Lucene query

executeSql(sql:branch:)

Execute a SQL query directly

Error Handling

Examples

SQL Queries

Execute SQL queries directly without needing a running server:

Idle Timeout

Last updated

Was this helpful?