Swift

SQLiteNow supports SwiftPM and Xcode apps by generating a local Swift package from SQL files in your app repository. Your app depends on the released SQLiteNow SwiftPM package for the generator, runs the sqlitenow-generate command plugin, then imports the generated package product from Swift code.

The generated package contains schema-specific Swift source. It depends on the released SQLiteNow package for support and runtime products: SQLiteNowCoreSupport/SQLiteNowCoreRuntime for core databases and SQLiteNowSyncSupport/SQLiteNowSyncRuntime for sync databases. App source imports the generated product, not the support or runtime modules.

Start Here

Use the getting-started guide to add SQLiteNow to a Swift package or Xcode app, create SQL files, configure SQLiteNow.json, generate the local package, and open/query the database:

Getting started

Use the configuration reference for SQLiteNow.json fields, default paths, runtime artifact options, regeneration behavior, and troubleshooting:

Configuration

Use the SQL reference for schema files, queries, migrations, dynamic fields, and generated Swift API shape:

SQL reference

Use recipes for custom adapters, reactive streams, inspection, parameter inference, and nested result mapping:

Recipes

Use the migration guide when changing schema after users already have installed databases:

Migration guide

Use the sync guide when your database participates in Oversqlite sync:

Swift sync

How It Fits Together

Replace X.Y.Z with the latest SQLiteNow release version.

dependencies: [
    .package(url: "https://github.com/mobiletoly/sqlitenow-kmp.git", from: "X.Y.Z"),
    .package(path: "SQLiteNowGenerated/AppDatabaseSQLiteNow"),
]

By default, authored SQL lives under:

SQLiteNow/databases/<databaseName>/
  schema/
  init/
  migration/
  queries/

The default generated package output path is:

SQLiteNowGenerated/<swiftPackageName>

App code imports the generated product:

import AppDatabaseSQLiteNow

Requirements

  • Apple Silicon macOS with Xcode command line tools; Intel macOS is unsupported
  • SwiftPM with swift-tools-version: 6.0 support
  • Java 17 or newer on PATH
  • A released SQLiteNow SwiftPM package version

The generator is distributed as a SwiftPM command plugin, but the compiler tool inside that plugin still runs on Java. A Java-free Swift generator is not part of the current Swift workflow.