SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Overview

SQLite.swift

Build Status CocoaPods Version Swift5 compatible Platform Carthage compatible Join the chat at https://gitter.im/stephencelis/SQLite.swift

A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Features

  • A pure-Swift interface
  • A type-safe, optional-aware SQL expression builder
  • A flexible, chainable, lazy-executing query layer
  • Automatically-typed data access
  • A lightweight, uncomplicated query and parameter binding interface
  • Developer-friendly error handling and debugging
  • Full-text search support
  • Well-documented
  • Extensively tested
  • SQLCipher support via CocoaPods
  • Active support at StackOverflow, and Gitter Chat Room (experimental)

Usage

("id") let name = Expression("name") let email = Expression("email") try db.run(users.create { t in t.column(id, primaryKey: true) t.column(name) t.column(email, unique: true) }) // CREATE TABLE "users" ( // "id" INTEGER PRIMARY KEY NOT NULL, // "name" TEXT, // "email" TEXT NOT NULL UNIQUE // ) let insert = users.insert(name <- "Alice", email <- "[email protected]") let rowid = try db.run(insert) // INSERT INTO "users" ("name", "email") VALUES ('Alice', '[email protected]') for user in try db.prepare(users) { print("id: \(user[id]), name: \(user[name]), email: \(user[email])") // id: 1, name: Optional("Alice"), email: [email protected] } // SELECT * FROM "users" let alice = users.filter(id == rowid) try db.run(alice.update(email <- email.replace("mac.com", with: "me.com"))) // UPDATE "users" SET "email" = replace("email", 'mac.com', 'me.com') // WHERE ("id" = 1) try db.run(alice.delete()) // DELETE FROM "users" WHERE ("id" = 1) try db.scalar(users.count) // 0 // SELECT count(*) FROM "users" ">
import SQLite

let db = try Connection("path/to/db.sqlite3")

let users = Table("users")
let id = Expression<Int64>("id")
let name = Expression<String?>("name")
let email = Expression<String>("email")

try db.run(users.create { t in
    t.column(id, primaryKey: true)
    t.column(name)
    t.column(email, unique: true)
})
// CREATE TABLE "users" (
//     "id" INTEGER PRIMARY KEY NOT NULL,
//     "name" TEXT,
//     "email" TEXT NOT NULL UNIQUE
// )

let insert = users.insert(name <- "Alice", email <- "[email protected]")
let rowid = try db.run(insert)
// INSERT INTO "users" ("name", "email") VALUES ('Alice', '[email protected]')

for user in try db.prepare(users) {
    print("id: \(user[id]), name: \(user[name]), email: \(user[email])")
    // id: 1, name: Optional("Alice"), email: [email protected]
}
// SELECT * FROM "users"

let alice = users.filter(id == rowid)

try db.run(alice.update(email <- email.replace("mac.com", with: "me.com")))
// UPDATE "users" SET "email" = replace("email", 'mac.com', 'me.com')
// WHERE ("id" = 1)

try db.run(alice.delete())
// DELETE FROM "users" WHERE ("id" = 1)

try db.scalar(users.count) // 0
// SELECT count(*) FROM "users"

SQLite.swift also works as a lightweight, Swift-friendly wrapper over the C API.

let stmt = try db.prepare("INSERT INTO users (email) VALUES (?)")
for email in ["[email protected]", "[email protected]"] {
    try stmt.run(email)
}

db.totalChanges    // 3
db.changes         // 1
db.lastInsertRowid // 3

for row in try db.prepare("SELECT id, email FROM users") {
    print("id: \(row[0]), email: \(row[1])")
    // id: Optional(2), email: Optional("[email protected]")
    // id: Optional(3), email: Optional("[email protected]")
}

try db.scalar("SELECT count(*) FROM users") // 2

Read the documentation or explore more, interactively, from the Xcode project’s playground.

SQLite.playground Screen Shot

For a more comprehensive example, see this article and the companion repository.

Installation

Note: Version 0.12 requires Swift 5 (and Xcode 10.2) or greater. Version 0.11.6 requires Swift 4.2 (and Xcode 10.1) or greater.

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa. To install SQLite.swift with Carthage:

  1. Make sure Carthage is installed.

  2. Update your Cartfile to include the following:

    0.12.0 ">
    github "stephencelis/SQLite.swift" ~> 0.12.0
  3. Run carthage update and add the appropriate framework.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install SQLite.swift with CocoaPods:

  1. Make sure CocoaPods is installed. (SQLite.swift requires version 1.6.1 or greater.)

    # Using the default Ruby install will require you to use sudo when
    # installing and updating gems.
    [sudo] gem install cocoapods
  2. Update your Podfile to include the following:

    use_frameworks!
    
    target 'YourAppTargetName' do
        pod 'SQLite.swift', '~> 0.12.0'
    end
  3. Run pod install --repo-update.

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code.

  1. Add the following to your Package.swift file:
dependencies: [
    .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.12.0")
]
  1. Build your project:
$ swift build

Manual

To install SQLite.swift as an Xcode sub-project:

  1. Drag the SQLite.xcodeproj file into your own project. (Submodule, clone, or download the project first.)

    Installation Screen Shot

  2. In your target’s General tab, click the + button under Linked Frameworks and Libraries.

  3. Select the appropriate SQLite.framework for your platform.

  4. Add.

Some additional steps are required to install the application on an actual device:

  1. In the General tab, click the + button under Embedded Binaries.

  2. Select the appropriate SQLite.framework for your platform.

  3. Add.

Communication

See the planning document for a roadmap and existing feature requests.

Read the contributing guidelines. The TL;DR (but please; R):

Author

License

SQLite.swift is available under the MIT license. See the LICENSE file for more information.

Related

These projects enhance or use SQLite.swift:

Alternatives

Looking for something else? Try another Swift wrapper (or FMDB):

Comments
  • CocoaPods fix: Xcode 7.3

    CocoaPods fix: Xcode 7.3

    This should hopefully fix issues #349 #378 and includes work from #379.

    Please test on your platform and report if it works!

    pod "SQLite.swift",
      git: "https://github.com/stephencelis/SQLite.swift",
      branch: "cocoapods-xcode-7-3"
    

    Will merge when things look good!

    cocoapods 
    opened by stephencelis 97
  • performance issue iterating over a query

    performance issue iterating over a query

    I'm having big performance issue iterating over a query, this is my code:

    func getPdfWithCategory(language:Language) -> CategoriesForLanguage {
            let categoriesForLanguage = CategoriesForLanguage()
    
            let PDFs = pdfDb!.pdfsTb.table
            let categories = pdfDb!.categoriesTb.table
            start = NSDate()
            let query = PDFs.select(PDFs[*], categories[pdfDb!.categoriesTb.id], categories[pdfDb!.categoriesTb.name], categories[pdfDb!.categoriesTb.thumb], categories[pdfDb!.categoriesTb.orderid])
    .join(categories, on: categories[pdfDb!.categoriesTb.id] == PDFs[pdfDb!.pdfsTb.categoryId])
    .filter(PDFs[pdfDb!.pdfsTb.languageId] == language.id)
    
            let timeInterval:NSTimeInterval = start!.timeIntervalSinceNow
            println("query \(timeInterval)")
    
            println("query count = \(query.count)")
    
            start = NSDate()
            for row in query {
    
            }
    
            let timeInterval2:NSTimeInterval = start!.timeIntervalSinceNow
            println("for row in query \(timeInterval2)")
            return categoriesForLanguage
        }
    

    and this is the print results:

    query -0.0109010338783264 query count = 88 for row in query -2.39910697937012

    I have even removed the join to see if it was that:

    func getPdfWithCategory(language:Language) -> CategoriesForLanguage {
            let categoriesForLanguage = CategoriesForLanguage()
    
            let PDFs = pdfDb!.pdfsTb.table
            let categories = pdfDb!.categoriesTb.table
            start = NSDate()
            let query = PDFs.select(PDFs[*]).filter(PDFs[pdfDb!.pdfsTb.languageId] == language.id)
    
            let timeInterval:NSTimeInterval = start!.timeIntervalSinceNow
            println("query \(timeInterval)")
    
            println("query count = \(query.count)")
    
            start = NSDate()
            for row in query {
    
            }
    
            let timeInterval2:NSTimeInterval = start!.timeIntervalSinceNow
            println("for row in query \(timeInterval2)")
            return categoriesForLanguage
        }
    

    it improved a little bit, but still too long:

    query -0.00782698392868042 query count = 88 for row in query -1.40383696556091

    P.S. I'm testing on a iPad

    enhancement 
    opened by violabg 47
  • Build fails with SQLCipher due to calls not yet available in SQLCipher

    Build fails with SQLCipher due to calls not yet available in SQLCipher

    commit 336faa1726887a90745e2949241394e41dd59be7 on Oct 8 added calls to sqlite3_expanded_sql and sqlite3_trace_v2.

    These are available in sqlite3 version 3.14, but not earlier versions. If you use SQLCipher upon which SQLiteCipher.swift is dependent, you get link errors because the version of sqlite3 used by SQLCipher is earlier than 3.14.

    opened by jimt2000 43
  • Build failing with Xcode 7.3 beta

    Build failing with Xcode 7.3 beta

    My configuration is:

    • Using latest Xcode 7.3 beta (7D129n)

    • Using latest version of Cocoapods (0.39.0)

    • with Podfile:

      use_frameworks!
      
      target 'app' do
      
      pod 'SQLite.swift'
      
      end
      

    I tried with or without xcode-select -s [PATH_TO_XCODE_BETA] or xcode-select -s [PATH_TO_XCODE], but they both failed by following reason:

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'Compression'
    module Compression [system] [extern_c] {
           ^
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1:8: note: previously defined here
    module Compression [system] [extern_c] {
           ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:6:8: error: redefinition of module 'Darwin'
    module Darwin [system] [extern_c] {
           ^
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:6:8: note: previously defined here
    module Darwin [system] [extern_c] {
           ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1478:8: error: redefinition of module 'os'
    module os [system] [extern_c] {
           ^
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1599:8: note: previously defined here
    module os [system] [extern_c] {
           ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1494:8: error: redefinition of module 'libkern'
    module libkern [system] [extern_c] {
           ^
    /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1615:8: note: previously defined here
    module libkern [system] [extern_c] {
           ^
    <unknown>:0: error: could not build Objective-C module 'SQLite'
    
    cocoapods 
    opened by vhain 33
  • Umbrella header SQLite.h not found in module.modulemap

    Umbrella header SQLite.h not found in module.modulemap

    I've updated XCode to the new version and I am trying to convert everything to use Swift 2.0. Unfortunately SQLite does not work anymore. I used the newest cocoapods (ver. 0.38.2) and i use this podfile: use_frameworks! pod 'SQLite.swift',git: 'https://github.com/stephencelis/SQLite.swift.git',branch: 'swift-2' But I receive always the above mentioned error. I tried to clean the Build Folder without success, always the same. Using the old version of SQLite.swift (copying the project in my project) with the old version of xcode was running like a charm. Now I have troubles using SQLite.swift. thanks arnold

    opened by arnoldschmid 30
  • Support for CocoaPods

    Support for CocoaPods

    Now that the current pre release version of CocoaPods supports Swift Frameworks I would like to ask if you could provide a podspec for Sqlite.swift.

    What do you think about this idea?

    enhancement help wanted 
    opened by skrach 24
  • Version 0.11.6

    Version 0.11.6

    Per recent discussion, this bumps the version to 0.11.6 and updates the project to Swift 5.

    First time contributing, so please forgive anything I've missed in this.

    One change in Foundation.swift I'm not 100% sure about because it required force unwrapping pointer.baseAddress within withUnsafeBytes, but I wasn't able to find anything less invasive to the current implementation.

    opened by sburlewapg 23
  • Broken CocoaPods instructions on the Swift 2 branch

    Broken CocoaPods instructions on the Swift 2 branch

    add SQLite.swift to my swift 2 application as the document in readme :

    pod 'SQLite.swift',
    git: 'https://github.com/stephencelis/SQLite.swift.git'
    
    # instead, for SQLCipher support
    pod 'SQLiteCipher.swift',
    git: 'https://github.com/stephencelis/SQLite.swift.git'
    

    but CocoaPods print:

    [!] Unable to find a specification for 'SQLiteCipher.swift'.
    

    why ? how to use SQLite.swift in swift 2 Application?

    question 
    opened by zixun 23
  • Can't use it with Mac.app

    Can't use it with Mac.app

    Hi,

    I tried your SQlite3 wrapper but was unable to get it to work with an Mac / Cocoa application. It would only work if the app was an iOS app to begin with. Could you tell what I am doing wrong? I added the framework just as depicted in your documentation. Regards Thomas bildschirmfoto 2015-01-17 um 17 06 53

    invalid 
    opened by thomasschoenfeld 23
  • Remove try! statement from FailableIterator

    Remove try! statement from FailableIterator

    My team has recently experienced crashes of an app in production related to SQLite.swift. Upon further review, we discovered that these crashes are occurring due to this try! encountering a throw from failableNext().

    This PR resolves the issue by returning nil if a throw is encountered.

    Here is the entire thread that crashes. Note that it occurs when using the Apollo-iOS framework, found here:

    Thread 7 name:
    Thread 7 Crashed:
    0   libswiftCore.dylib            	0x000000010117f968 0x100fa0000 + 1964392
    1   libswiftCore.dylib            	0x000000010117f968 0x100fa0000 + 1964392
    2   libswiftCore.dylib            	0x000000010102f994 0x100fa0000 + 588180
    3   SQLite                        	0x0000000100d7e80c _T06SQLite16FailableIteratorPAAE4next7ElementQzSgyFAA9StatementC_Tg5 + 212 (Statement.swift:211)
    4   SQLite                        	0x0000000100d674c8 _T06SQLite10ConnectionC7prepares11AnySequenceVyAA3RowVGAA9QueryType_pKFs0D8IteratorVyAHGycfU_AHSgycfU_TA + 76 (Query.swift:927)
    5   SQLite                        	0x0000000100d67578 _T06SQLite3RowVSgIxo_ADIxr_TRTA + 48 (Query.swift:0)
    6   libswiftCore.dylib            	0x000000010114e9bc 0x100fa0000 + 1763772
    7   libswiftCore.dylib            	0x000000010114e9fc 0x100fa0000 + 1763836
    8   libswiftCore.dylib            	0x000000010114ead0 0x100fa0000 + 1764048
    9   libswiftCore.dylib            	0x000000010102a8c8 0x100fa0000 + 567496
    10  libswiftCore.dylib            	0x000000010114e16c 0x100fa0000 + 1761644
    11  libswiftCore.dylib            	0x000000010118fd78 0x100fa0000 + 2030968
    12  libswiftCore.dylib            	0x0000000100fa8774 0x100fa0000 + 34676
    13  libswiftCore.dylib            	0x000000010115f5bc 0x100fa0000 + 1832380
    14  libswiftCore.dylib            	0x000000010114f4fc 0x100fa0000 + 1766652
    15  Apollo                        	0x0000000100a01c3c _T06Apollo21SQLiteNormalizedCacheC13selectRecords33_0382DE2BE0B0836588D3F2CA65C602E7LLSayAA6RecordVGSaySSG7forKeys_tKFTf4gn_n + 1284 (SQLiteNormalizedCache.swift:0)
    16  Apollo                        	0x0000000100a02710 _T06Apollo21SQLiteNormalizedCacheC12mergeRecords33_0382DE2BE0B0836588D3F2CA65C602E7LLs3SetVySSGAA06RecordO0V7records_tKFTf4gn_n + 116 (SQLiteNormalizedCache.swift:0)
    17  Apollo                        	0x0000000100a031c8 _T06Apollo21SQLiteNormalizedCacheC5mergeAA7PromiseCys3SetVySSGGAA06RecordG0V7records_tFTf4gn_n + 304 (SQLiteNormalizedCache.swift:0)
    18  Apollo                        	0x00000001009ff290 _T06Apollo21SQLiteNormalizedCacheCAA0cD0A2aDP5mergeAA7PromiseCys3SetVySSGGAA06RecordG0V7records_tFTW + 44 (SQLiteNormalizedCache.swift:0)
    19  Apollo                        	0x000000010099d1ec _T06Apollo0A5StoreC7publishAA7PromiseCyytGAA9RecordSetV7records_SvSg7contexttFyyyc_ys5Error_pctcfU_yycfU_Tf4ggng_n + 164 (ApolloStore.swift:52)
    20  Apollo                        	0x000000010099f788 _T06Apollo0A5StoreC7publishAA7PromiseCyytGAA9RecordSetV7records_SvSg7contexttFyyyc_ys5Error_pctcfU_yycfU_TA + 104 (ApolloStore.swift:0)
    21  Apollo                        	0x00000001009c0f1c _T0Ix_IyB_TR + 36 (GraphQLQueryWatcher.swift:0)
    22  libdispatch.dylib             	0x00000001812b2a54 _dispatch_call_block_and_release + 24 (init.c:994)
    23  libdispatch.dylib             	0x00000001812b2a14 _dispatch_client_callout + 16 (object.m:502)
    24  libdispatch.dylib             	0x00000001812c1540 _dispatch_queue_concurrent_drain + 540 (inline_internal.h:2500)
    25  libdispatch.dylib             	0x00000001812bd304 _dispatch_queue_invoke$VARIANT$mp + 348 (queue.c:5304)
    26  libdispatch.dylib             	0x00000001812bfcf4 _dispatch_root_queue_drain + 600 (inline_internal.h:2539)
    27  libdispatch.dylib             	0x00000001812bfa38 _dispatch_worker_thread3 + 120 (queue.c:6104)
    28  libsystem_pthread.dylib       	0x000000018155b06c _pthread_wqthread + 1268 (pthread.c:2286)
    29  libsystem_pthread.dylib       	0x000000018155ab6c start_wqthread + 4
    
    opened by ethansinjin 21
  • Xcode 12 Beta SQLite.swift Can't Build

    Xcode 12 Beta SQLite.swift Can't Build

    Issues are used to track bugs and feature requests. Need help or have a general question? Ask on Stack Overflow (tag sqlite.swift).

    Build Information

    • Include the SQLite.swift version, commit or branch experiencing the issue.
    • Mention Xcode and OS X versions affected.
    • How do do you integrate SQLite.swift in your project?
      • CocoaPods

    General guidelines

    • Be as descriptive as possible.
    • Provide as much information needed to reliably reproduce the issue.
    • Attach screenshots if possible.
    • Better yet: attach GIFs or link to video.
    • Even better: link to a sample project exhibiting the issue.

    image

    image

    opened by RuoG 19
  • Support for SQLite 3.35.0 or above

    Support for SQLite 3.35.0 or above

    Build Information

    • SQLite.swift version: 0.14.1 -> master branch
    • Xcode: 14.2 and OS X: 16.2
    • Installed the lib with Swift Package manager

    Is there a way to include the SQLite >3.35.0 version, because I want to use the trigonometric function like sin, cos or acos in a sql query.

    At the moment with the latest version of SQLite.swift I get following error:

    no such function: acos (code: 1)

    A example for the query I use:

    SELECT *, ( 6371 * acos ( cos ( radians(LOCATIONLAT) ) * cos( radians( p.p_lat ) ) * cos( radians( p.P_LNG ) - radians(LOCATIONLNG) ) + sin ( radians(LOCATIONLAT) ) * sin( radians( p.p_lat ) ) ) ) AS distance FROM table p where distance < 15.0 ORDER BY distance

    it calculates the distance in km between two points.

    In my sqlitedatabase browser it works and it use the 3.39.4 version of SQLite.

    FYI: the SQLite version of iOS 16.2 is 3.39.5

    opened by androidseb25 0
  • Class SQLiteXXX is implemented in both LinkServices.framework and MyApp error logs

    Class SQLiteXXX is implemented in both LinkServices.framework and MyApp error logs

    Build Information

    • SQLite.swift 0.14.1
    • Xcode 14.1 (14B47b) / macOS 12.6.1 (21G217)
    • Swift Package manager

    Issue

    Hi,

    We're seeing worrisome errors from the ObjC runtime in our logs when running an app linking both SQLite.swift and the PSPDFKit framework (https://github.com/PSPDFKit/PSPDFKit-SP / https://pspdfkit.com):

    Class _TtC6SQLite6Backup is implemented in both /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1b8c21b70) and /[redacted]/SQLiteConnectionConflict.app/SQLiteConnectionConflict (0x1005a6538). One of the two will be used. Which one is undefined. 
    

    This is reported for several classes : SQLiteBackup, SQLiteConnection, SQLiteStatement, SQLiteTableBuilder.

    Full logs
    objc[67969]: Class _TtC6SQLite6Backup is implemented in both /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1b8c21b70) and /[redacted]/SQLiteConnectionConflict.app/SQLiteConnectionConflict (0x100c26538). One of the two will be used. Which one is undefined.
    objc[67969]: Class _TtC6SQLite10Connection is implemented in both /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1b8c218a8) and /[redacted]/SQLiteConnectionConflict.app/SQLiteConnectionConflict (0x100c26788). One of the two will be used. Which one is undefined.
    objc[67969]: Class _TtC6SQLite9Statement is implemented in both /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1b8c21aa0) and /[redacted]/SQLiteConnectionConflict.app/SQLiteConnectionConflict (0x100c26948). One of the two will be used. Which one is undefined.
    objc[67969]: Class _TtC6SQLite12TableBuilder is implemented in both /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1b8c21460) and /[redacted]/SQLiteConnectionConflict.app/SQLiteConnectionConflict (0x100c27ef0). One of the two will be used. Which one is undefined.
    

    You can reproduce the issue by creating a new iOS app in Xcode, and adding both SQLite.swift and PSPDFKit to the app with SwiftPM. A sample project is attached. Run the app and the message will immediately appear in the logs.

    Can you help us understand why this error is reported and how we should fix it please?

    Thanks for your help!

    PS: This issue has also been reported to the PSPDFKit team, I'll update here if I get some updates on the other side.

    SQLiteConnectionConflict.zip

    opened by guillaumealgis 1
  • Reactive functionality

    Reactive functionality

    Hello!

    I made my application with SQLite, SwiftUI, Combine, MVVM, etc.

    Issue

    And I needed some feature to refresh view when the database table changes in my app.

    I implemented like,

    • user clicks a button
    • then, app inserts some data to DB
    • to do refresh work, app selects from DB

    And I encountered an error, saying "database is locked (code: 5)", like below.

    스크린샷 2022-11-17 오후 7 00 13

    The app crashed when I try select action right after insert action.

    And I searched about this error, and I got some clue at this. -> Link

    The problem was "conflict between two transactions running on the same database connection".

    So, to fix this problem, I want to make the select work is done definitely after insert work.

    Therefore, some reactive functionality can be helpful, so that only when the database table changes, app does select action again to refresh view.

    Is there any technique to help reactive view refresh in point of SQLite local DB?

    I found some possible method,

    • using NotificationCenter and updateHook() method

    But, I have no idea how to actually implement like this. I need more detailed explain...

    Build Information

    I added SQLite version 0.13.2 with CocoaPods.

    'SQLite.swift', '~> 0.13.2'

    And I use Xcode version 14.1, macOS Monterey version 12.6.

    Related Issue

    I checked issue #686,
    and I hope to know more information about that.

    Any clues will be helpful.

    With Love 🫶,
    Thank you.

    opened by imseonho 0
  • Update behaviour: swift Codable with Optional fields

    Update behaviour: swift Codable with Optional fields

    In some past SQLiteEncoder skips to update the column if the Codable's optional field is nil Seems after https://github.com/stephencelis/SQLite.swift/issues/838 it starts to place null if the value is nil, which is not convenient in some cases (often you want to update only part of the fields)

    Please provide either

    • example/docs how to update only non-nil fields
    • additional Encoder setting that would configure this behaviour
    opened by Alkenso 2
  • Add TableBuilder overloads for two and three element foreign key constraints with optional values

    Add TableBuilder overloads for two and three element foreign key constraints with optional values

    The TableBuilder supports foreign key constraints with optional values for single column foreign keys. It also supports overloads for 2 and 3 column keys with no optional values. We ended up needing a bunch of different combinations of 2 and 3 column foreign keys with optional values in various places for a project.

    This PR includes those extra overloads as well as a documentation example for how to use the multi-column foreign key support already in TableBuilder (which we ended up having to reference the code to figure out how to use).

    opened by zaphoyd 1
  • SQLite Encryption Extension

    SQLite Encryption Extension

    If we used SQLite Encryption Extension we purchased and built it into our SDK product, how do we use SQlite. swift I watched the https://sqlite.org/com/see.html

    opened by liyuan116 0
Releases(0.14.1)
Owner
Stephen Celis
Working on @pointfreeco: https://www.pointfree.co/
Stephen Celis
GRDB - A toolkit for SQLite databases, with a focus on application development

A toolkit for SQLite databases, with a focus on application development Latest release: May 16, 2021 • version 5.8.0 • CHANGELOG • Migrating From GRDB

Gwendal Roué 5.6k Dec 30, 2022
MySQL client library for Swift. This is inspired by Node.js' mysql.

mysql-swift MySQL client library for Swift. This is inspired by Node.js' mysql. Based on libmysqlclient Raw SQL query Simple query formatting and esca

Yusuke Ito 155 Nov 19, 2022
Perfect - a Swift wrapper around the MySQL client library, enabling access to MySQL database servers.

Perfect - MySQL Connector This project provides a Swift wrapper around the MySQL client library, enabling access to MySQL database servers. This packa

PerfectlySoft Inc. 119 Dec 16, 2022
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Perfect - PostgreSQL Connector This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. This pack

PerfectlySoft Inc. 51 Nov 19, 2022
🔥 🔥 🔥Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

?? ?? ??Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

null 60 Dec 12, 2022
Demonstration code for a simple Swift property-wrapper, keypath-based dependency injection system. The keypaths ensure compile-time safety for all injectable services.

Injectable Demo Preliminary musings and demonstration code for a simple Swift property-wrapper, keypath-based dependency injection system. The keypath

Michael Long 12 Aug 5, 2022
Needle - Compile-time safe Swift dependency injection framework

Needle is a dependency injection (DI) system for Swift. Unlike other DI frameworks, such as Cleanse, Swinject, Needle encourages hierarchical DI struc

Uber Open Source 1.4k Jan 3, 2023
Toledo - a dependency injection library for Swift that statically generates resolvers at compile-time.

Toledo Toledo is a dependency injection library for Swift that statically generates resolvers at compile-time. Index Features Installation Usage Licen

Valentin Radu 18 Nov 25, 2022
Compile-time-checked URLs

SafeURL Tool for avoiding using the URL(string:) initializer with optional result, instead introducing a compile time URL validity check. Note, this d

Jhonatan A. 134 Dec 10, 2022
Sharing SQL queries between Server and Mobile databases

Sharing SQL queries between Server and Mobile databases Overview As we all know, code is expensive to maintain, and the more complex the code, the mor

Aaron LaBeau 4 May 24, 2022
An alternative to Core Data for people who like having direct SQL access.

FCModel 2 An alternative to Core Data for people who like having direct SQL access. By Marco Arment. See the LICENSE file for license info (it's the M

null 1.7k Dec 28, 2022
This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD

Apress Source Code This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD by Gio Lodi (Apress, 2021). D

Apress 57 Jan 1, 2023
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger.

MetalCompilerPlugin Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger. Description Swift Package Manag

Jonathan Wight 10 Oct 30, 2022
Discover, download, compile & launch different image processing & style transfer CoreML models on iOS.

⚠️ ⚠️ ⚠️ IMPORTANT: I'm no longer maintaining Awesome-ML. Awesome ML is an iOS app that is made to demonstrate different image processing CoreML model

eugene 171 Nov 8, 2022
Awesome-ML - Discover, download, compile & launch different image processing & style transfer CoreML models on iOS.

⚠️ ⚠️ ⚠️ IMPORTANT: I'm no longer maintaining Awesome-ML. Awesome ML is an iOS app that is made to demonstrate different image processing CoreML model

eugene 171 Nov 8, 2022
SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It's time to get rid of Objective-C cruft.

SwiftyTimer Modern Swifty API for NSTimer SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It

Radek Pietruszewski 1.2k Dec 27, 2022
SQLiteDB is a simple and lightweight SQLite wrapper for Swift

Basic SQLite wrapper for Swift 4.x and lightweight ORM for accessing underlying tables in an SQLite database

Fahim Farook 559 Jan 4, 2023
SQLite.swift - A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Stephen Celis 8.7k Jan 3, 2023