WHC_ModelSqliteKit Documentation

Welcome to the documentation for WHC_ModelSqliteKit! This library provides a convenient and efficient way to use SQLite database in your iOS projects. It offers a set of tools and utilities to simplify database operations and improve performance. Whether you are new to SQLite or an experienced developer, this documentation will guide you through the essentials of using WHC_ModelSqliteKit effectively in your iOS app.


To use WHC_ModelSqliteKit in your project, follow these steps:

  • Open your project in Xcode.
  • Go to “File” > “Swift Packages” > “Add Package Dependency”.
  • Enter the following URL: https://github.com/netyouli/WHC_ModelSqliteKit.git
  • Choose the latest available version of WHC_ModelSqliteKit.
  • Click “Next” and then “Finish”.

Quick Start

To get started with WHC_ModelSqliteKit, follow these steps:

  1. Create a new SQLite database:

import WHC_ModelSqliteKit
let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/TestDB.sqlite"
if let database = WHC_ModelSqlite.createDatabase(databasePath: databasePath) {
    // Database created successfully
} else {
    // Error creating database

Next, create a table and model:

class Person: WHC_SqliteModel {
    var name = ""
    var age = 0
WHC_ModelSqlite.createTable(modelClass: Person.self, dbName: databasePath, needVerify: true)

Finally, insert, update, or query the database using model objects:

let person = Person()
person.name = "John"
person.age = 25
let insertResult = WHC_ModelSqlite.insert(model: person)
if insertResult.result {
    // Insert successful
} else {
    // Insert failed

let updateResult = WHC_ModelSqlite.update(model: person,
                                          where: "name = 'John'",
                                          dbName: databasePath)
if updateResult.result {
    // Update successful
} else {
    // Update failed

let queryResult = WHC_ModelSqlite.query(model: Person.self,
                                        where: "age > 20",
                                        dbName: databasePath) as? [Person]
if let results = queryResult {
    // Use the query results
} else {
    // Query failed

Key Features

  • Automatic mapping: WHC_ModelSqliteKit automatically maps model properties to database columns, saving you from writing repetitive code.
  • Efficient queries: Perform complex queries with ease using WHC_ModelSqliteKit’s powerful query API.
  • Concurrency support: WHC_ModelSqliteKit handles concurrent database operations and ensures data integrity.
  • Data migration: Easily migrate database schema and upgrade data models without losing any data.


With WHC_ModelSqliteKit, you can leverage the power of SQLite in your iOS app without the hassle of manual database management. Start using WHC_ModelSqliteKit today and simplify your database operations!