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

Related tags

Database swift sqlite
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
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

?? Easy to use SQLite ORM library written with Swift

Yevgeniy Zakharov 25 Oct 6, 2022
A Swift library to fetch the schema from a SQLite3 database.

SQLite3Schema A small library to fetch the schema of a SQLite database. Contains a SQLite3 helper module for Linux. TBD. Uses just the raw SQLite API.

Helge Heß 4 Sep 17, 2022
🛶Shallows is a generic abstraction layer over lightweight data storage and persistence.

Shallows Shallows is a generic abstraction layer over lightweight data storage and persistence. It provides a Storage<Key, Value> type, instances of w

Oleg Dreyman 620 Dec 3, 2022
A lightweight wrapper over UserDefaults/NSUserDefaults with an additional layer of AES-256 encryption

SecureDefaults for iOS, macOS Requirements • Usage • Installation • Contributing • Acknowledgments • Contributing • Author • License SecureDefaults is

Victor Peschenkov 216 Dec 22, 2022
YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers.

YapDatabase is a collection/key/value store and so much more. It's built atop sqlite, for Swift & Objective-C developers, targeting macOS, iOS, tvOS &

Yap Studios 3.3k Dec 29, 2022
A Swift wrapper for SQLite databases

Squeal, a Swift interface to SQLite Squeal provides access to SQLite databases in Swift. Its goal is to provide a simple and straight-forward base API

Christian Niles 297 Aug 6, 2022
A stand-alone Swift wrapper around the SQLite 3 client library.

Perfect - SQLite Connector This project provides a Swift wrapper around the SQLite 3 library. This package builds with Swift Package Manager and is pa

PerfectlySoft Inc. 47 Nov 19, 2022
A toolkit for SQLite databases, with a focus on application development

A toolkit for SQLite databases, with a focus on application development

Gwendal Roué 5.6k Jan 8, 2023
Realm is a mobile database: a replacement for Core Data & SQLite

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the iOS, macOS, tvOS & wa

Realm 15.7k Jan 1, 2023
A Cocoa / Objective-C wrapper around SQLite

FMDB v2.7 This is an Objective-C wrapper around SQLite. The FMDB Mailing List: https://groups.google.com/group/fmdb Read the SQLite FAQ: https://www.s

August 13.7k Dec 28, 2022
Implement Student Admission System using SQlite

StudentAdmissionSQLiteApp Implement Student Admission System using SQlite. #Func

Hardik 2 Apr 27, 2022
BucketServer - Small API with SQLite database that saves notes for an iOS appliction called Bucket list

BucketList Server-Side Small API with SQLite database that saves notes for an iO

null 0 Dec 30, 2021
macOS Sqlite tableView 샘플 - objective c

목적 Objective C언어를 이용하여 macOS를 개발해본다. Sqlite를 이용하여 데이터를 저장하고, 불러와본다. FMDB를 이용한다. 데이터를 NSTableView를 이용하여 불러와본다. 추가적으로 NSOutlineView 구현해본다. 추가적으로 KVOCont

HyunSu Park 0 Jan 10, 2022
MagicData - A replacement of SQlite, CoreData or Realm.

MagicData A replacement of SQlite, CoreData or Realm. It is very easy to use and is a light version. Guides MagicData We use MagicData manage all the

Underthestars-zhy 20 Jul 4, 2022
A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

There are many libraries out there that aims to help developers easily create and use SQLite databases. Unfortunately developers still have to get bogged down in simple tasks such as writing table definitions and SQL queries. SwiftyDB automatically handles everything you don't want to spend your time doing.

Øyvind Grimnes 489 Sep 9, 2022
A protocol-centric, type and queue safe key-value workflow.

Light-weight, strict protocol-first styled PropertyKit helps you to easily and safely handle guaranteed values, keys or types on various situations of

gitmerge 12 Feb 26, 2021
A Swift wrapper for system shell over posix_spawn with search path and env support.

AuxiliaryExecute A Swift wrapper for system shell over posix_spawn with search path and env support. Usage import AuxiliaryExecute AuxiliaryExecute.l

Lakr Aream 11 Sep 13, 2022
Effortlessly synchronize UserDefaults over iCloud.

Zephyr ??️ Effortlessly sync UserDefaults over iCloud About Zephyr synchronizes specific keys and/or all of your UserDefaults over iCloud using NSUbiq

Arthur Ariel Sabintsev 841 Dec 23, 2022
Nora is a Firebase abstraction layer for FirebaseDatabase and FirebaseStorage

Nora is a Firebase abstraction layer for working with FirebaseDatabase and FirebaseStorage. Stop spending all that time cleaning up your view controll

Steven Deutsch 273 Oct 15, 2022