Skip to content

Latest commit

 

History

History
132 lines (95 loc) · 3.81 KB

File metadata and controls

132 lines (95 loc) · 3.81 KB

Feather Database SQLite

SQLite driver implementation for the abstract Feather Database Swift API package.

Release: 1.0.0-rc.2

Features

  • SQLite driver for Feather Database
  • Automatic query parameter escaping via Swift string interpolation.
  • Async sequence query results with Decodable row support.
  • Designed for modern Swift concurrency
  • DocC-based API Documentation
  • Unit tests and code coverage

Requirements

Swift 6.1+ Platforms: Linux, macOS, iOS, tvOS, watchOS, visionOS

  • Swift 6.1+
  • Platforms:
    • Linux
    • macOS 15+
    • iOS 18+
    • tvOS 18+
    • watchOS 11+
    • visionOS 2+

Installation

Add the dependency to your Package.swift:

.package(url: "https://github.com/feather-framework/feather-database-sqlite", exact: "1.0.0-rc.2"),

Then add FeatherDatabaseSQLite to your target dependencies:

.product(name: "FeatherDatabaseSQLite", package: "feather-database-sqlite"),

Package traits

This package offers additional integrations you can enable using package traits. To enable an additional trait on the package, update the package dependency:

.package(
    url: "https://github.com/feather-framework/feather-database-sqlite",
    exact: "1.0.0-rc.2",
+   traits: [
+       .defaults, 
+       "ServiceLifecycle",
+   ]
)

Available traits:

  • ServiceLifecycle (default): Adds support for DatabaseServiceSQLite, a ServiceLifecycle.Service implementation for managing SQLite clients.

Usage

API documentation is available at the link below:

DocC API documentation

Here is a brief example:

import Logging
import SQLiteNIO
import SQLiteNIOExtras
import FeatherDatabase
import FeatherDatabaseSQLite

try await withLogger(Logger(label: "example")) { _ in
    let configuration = SQLiteClient.Configuration(
        storage: .file(path: "/Users/me/db.sqlite")
    )

    let client = SQLiteClient(configuration: configuration)

    let database = DatabaseClientSQLite(
        client: client
    )

    try await client.run()

    let result = try await database.withConnection { connection in
        try await connection.run(
            query: #"""
                SELECT
                    sqlite_version() AS "version"
                WHERE
                    1=\#(1);
                """#
        )
    }

    for try await item in result {
        let version = try item.decode(column: "version", as: String.self)
        print(version)
    }

    await client.shutdown()
}

The package uses Logger.current from swift-log for database logging. Use withLogger to scope the logger for an operation; calls to Logger.current within that scope use the scoped logger.

Other database drivers

The following database driver implementations are available for use:

Development

  • Build: swift build
  • Test:
    • local: swift test
    • using Docker: make docker-test
  • Format: make format
  • Check: make check

Contributing

Pull requests are welcome. Please keep changes focused and include tests for new logic.