Skip to content

TriCoreDB for Swift

v0.1.0

The official Swift client: SQL, documents, cache, vectors and graphs over one native connection.

Install

Package.swift
dependencies: [
    .package(url: "https://github.com/trinesh14/tricoredb-sdk-swift", from: "0.1.0")
],
targets: [
    .target(name: "YourApp", dependencies: [
        .product(name: "TriCoreDB", package: "tricoredb-sdk-swift")
    ])
]

Requirements

  • Swift 5.9 or later
  • macOS 13+, iOS 16+, or Linux
  • A TriCoreDB server, 0.1.0-rc.1 or later (install one)

Highlights

  • async / await API
  • Built on SwiftNIO, with TLS on Apple platforms and Linux
  • Transactions, connection pool, TLS and mutual TLS

Quick start

main.swift
import TriCoreDB

let db = try await TriCore.connect(host: "127.0.0.1", port: 8427, user: "admin", secret: "your-password")

try await db.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT)")
try await db.execute("INSERT INTO users VALUES (?, ?)", [1, "O'Hara"])

let rows = try await db.query("SELECT id, name FROM users WHERE id = ?", [1])
print(rows.value(row: 0, column: "name") ?? "")   // O'Hara

try await db.cacheSet("sessions", "u1", "token")
let token = try await db.cacheGet("sessions", "u1")   // nil on a miss
await db.close()

TLS

This example connects without TLS, which matches the development container. The default image requires TLS. The README shows how to connect with a CA certificate, and documents every call.