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 column = [Column.init(ColumnName: "ID", dataType: .int , isPrimary: .primary , isUnique: .notUnique)!,
Column.init(ColumnName: "Name", dataType: .string , isPrimary: .notPrimary , isUnique: .notUnique)!,
Column.init(ColumnName: "Mail", dataType: .string , isPrimary: .notPrimary , isUnique: .unique)!,
Column.init(ColumnName: "Mobile", dataType: .string , isPrimary: .notPrimary , isUnique: .unique)!]
let aa = createTable(tableName: "fourth_table", DB: self.data_base, columnNames: column)
if (aa.success) {
print("table created")
}
else{
print("Error while creating table\(aa.error!)")
}
let columnInsert = [Column.init(ColumnName: "Name", dataType: .string , isPrimary: .notPrimary , isUnique: .notUnique, value: "Sureshkumar")!,
Column.init(ColumnName: "Mail", dataType: .string , isPrimary: .notPrimary , isUnique: .unique, value: "sureshkumar.r@osoftz.com")!,
Column.init(ColumnName: "Mobile", dataType: .string , isPrimary: .notPrimary , isUnique: .unique, value: "245678512")!]
let bb = insertInTable(tableName: "fourth_table", DB: self.data_base, columnNames: columnInsert)
if(bb.success){
let ID = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "ID", dataType: .int)!)
let Name = selectTable(DB: self.data_base, tableName: "fourth_table",column: Column.init(ColumnName: "Name", dataType: .int)!)
let Mobile = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mail", dataType: .int)!)
let Email = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mobile", dataType: .int)!)
if Name.error == nil{
print("ID in fourth table\(ID.value!)\nNames array \(Name.value!)\nMobile \(Mobile.value!)\nEmail \(Email.value!)")
}
}
else{
print("Error while inserting \(bb.error!)")
}
/* *********************Creating and print Table************************* */
/* *********************Upadte and print Table************************* */
let cc = updateTable(DB: self.data_base, tableName: "fourth_table",column: Column.init(ColumnName: "Mobile", dataType: .string, value: "9876543210", wrCN: "ID", wrVal: "1", wrDT: .int)!)
if(cc.success){
let ID = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "ID", dataType: .int)!)
let Name = selectTable(DB: self.data_base, tableName: "fourth_table",column: Column.init(ColumnName: "Name", dataType: .string)!)
let Mobile = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mail", dataType: .string)!)
let Email = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mobile", dataType: .string)!)
if Name.error == nil{
print("ID in fourth table\(ID.value!)\nNames array \(Name.value!)\nMobile \(Mobile.value!)\nEmail \(Email.value!)")
}
}
else{
print("Error while update \(cc.error!)")
}
/* *********************Creating and print Table************************* */
let dd = deleteRow(DB: self.data_base, tableName: "fourth_table",column: Column.init(ColumnName: "ID" , dataType: .int, value: "1")!)
if (dd.success){
let ID = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "ID", dataType: .int)!)
let Name = selectTable(DB: self.data_base, tableName: "fourth_table",column: Column.init(ColumnName: "Name", dataType: .string)!)
let Mobile = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mail", dataType: .string)!)
let Email = selectTable(DB: self.data_base, tableName: "fourth_table", column: Column.init(ColumnName: "Mobile", dataType: .string)!)
if Name.error == nil{
print("ID in fourth table\(ID.value!)\nNames array \(Name.value!)\nMobile \(Mobile.value!)\nEmail \(Email.value!)")
}
}
else{
print("Error while Delete \(dd.error!)")
}
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: "1.0.7")
]
- 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 sqliteClasses 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 sqliteClasses.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.
- [Osoftz(mailto:ios@osoftz.com)
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):