A type-safe, Swift-language layer over SQLite3.
sqliteClasses provides compile-time confidence in SQL statement syntax and intent.
- 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)
/* *********************Creating and Assigning DB************************* */
createDB(DBName: "First_DB"){
data, error in
if data == nil && error == nil{
print("Table not created")
}
else if data == nil{
print(error!)
}
else{
self.data_base = data!
print("Database created")
}
}
/* *********************Creating and Assigning DB************************* */
/* *********************Creating and print Table************************* */
let columnNames = ["ID","Name","Age","Mobile","Mail"]
let dataType = [0,2,2,2,2]
let unique = [false,false,false,true,true]
let primay = [true,false,false,false,false]
let aa = createTable(tableName: "SecondTable", DB: self.data_base, columnNames: columnNames, dataType: dataType, isUnique: unique, isPrimary: primay)
if (aa.0) {
print("table created")
}
else{
print("Error while creating table\(aa.1!)")
}
let columnNames1 = ["Name","Age","Mobile","Mail"]
let dataType1 = [2,2,2,2]
let values = ["Siva","28","96684579","[email protected]"]
let bb = insertInTable(tableName: "SecondTable", DB: self.data_base, columnNames: columnNames1, dataType: dataType1, values: values)
if(bb.0){
let ID = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 0, column: "ID")
let Name = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Name")
let Age = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Age")
let Mobile = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mobile")
let Email = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mail")
if Name.1 == nil{
print("ID \(ID.0!)\nNames array \(Name.0!)\nAge \(Age.0!)\nMobile \(Mobile.0!)\nEmail \(Email.0!)")
}
}
else{
print("Error while inserting \(bb.1!)")
}
/* *********************Creating and print Table************************* */
/* *********************Upadte and print Table************************* */
let cc = updateTable(DB: self.data_base, tableName: "SecondTable", where_columName: "ID", where_value: "2", where_dataType: 0, columName: "Name", value: "Sureshkumar", dataType: 2)
if(cc.0){
let ID = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 0, column: "ID")
let Name = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Name")
let Age = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Age")
let Mobile = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mobile")
let Email = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mail")
if Name.1 == nil{
print("ID \(ID.0!)\nNames array \(Name.0!)\nAge \(Age.0!)\nMobile \(Mobile.0!)\nEmail \(Email.0!)")
}
}
else{
print("Error while update \(cc.1!)")
}
/* *********************Creating and print Table************************* */
let dd :(Bool?, Error?) = deleteRow(DB: self.data_base, tableName: "SecondTable", dataType: 0, column: "ID", value: "1")
if (dd.0!){
let ID = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 0, column: "ID")
let Name = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Name")
let Age = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Age")
let Mobile = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mobile")
let Email = selectTable(DB: self.data_base, tableName: "SecondTable", dataType: 2, column: "Mail")
if Name.1 == nil{
print("ID \(ID.0!)\nNames array \(Name.0!)\nAge \(Age.0!)\nMobile \(Mobile.0!)\nEmail \(Email.0!)")
}
}
else{
print("Error while Delete \(dd.1!)")
}
Read the documentation or explore more, interactively, from the Xcode project’s playground.
For a more comprehensive example, see this article and the companion repository.
Note: sqliteClasses requires Swift 4.1 (and Xcode 9.3).
Carthage is a simple, decentralized dependency manager for Cocoa. To install sqliteClasses with Carthage:
-
Make sure Carthage is installed.
-
Update your Cartfile to include the following:
github "osoftz/sqliteClasses"
-
Run
carthage update
and add the appropriate framework.
CocoaPods is a dependency manager for Cocoa projects. To install sqliteClasses with CocoaPods:
-
Make sure CocoaPods is installed. (sqliteClasses requires version 1.0.0 or greater.)
# Using the default Ruby install will require you to use sudo when # installing and updating gems. [sudo] gem install cocoapods
-
Update your Podfile to include the following:
use_frameworks! target 'YourAppTargetName' do pod 'sqliteClasses' end
-
Run
pod install --repo-update
.
The Swift Package Manager is a tool for managing the distribution of Swift code.
- Add the following to your
Package.swift
file:
dependencies: [
.package(url: "https://github.com/osoftz/sqliteClasses.git", from: "0.11.5")
]
- Build your project:
$ swift build
To install sqliteClasses as an Xcode sub-project:
-
Drag the SQLite.xcodeproj file into your own project. (Submodule, clone, or download the project first.)
-
In your target’s General tab, click the + button under Linked Frameworks and Libraries.
-
Select the appropriate SQLite.framework for your platform.
-
Add.
Some additional steps are required to install the application on an actual device:
-
In the General tab, click the + button under Embedded Binaries.
-
Select the appropriate SQLite.framework for your platform.
-
Add.
See the planning document for a roadmap and existing feature requests.
Read the contributing guidelines. The TL;DR (but please; R):
- Need help or have a general question? Ask on Stack
Overflow (tag
sqlite.swift
). - Found a bug or have a feature request? Open an issue.
- Want to contribute? Submit a pull request.
sqliteClasses is available under the MIT license. See the LICENSE file for more information.
These projects enhance or use sqliteClasses:
- SQLiteMigrationManager.swift (inspired by FMDBMigrationManager)
Looking for something else? Try another Swift wrapper (or FMDB):