Skip to content
Use SQLite now is easy!
Objective-C Swift Ruby
Branch: master
Clone or download
Latest commit 9efe49d Nov 20, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Add .deleteData; Improve documentation Nov 20, 2019
NAMDatabase Add .deleteData; Improve documentation Nov 20, 2019
.gitignore Initial commit Nov 19, 2019
.travis.yml Initial commit Nov 19, 2019
LICENSE Initial commit Nov 19, 2019
NAMDatabase.podspec Add .deleteData; Improve documentation Nov 20, 2019 Fix typo in README Nov 20, 2019
_Pods.xcodeproj Initial commit Nov 19, 2019


Version License Platform Twitter


NAMDatabase is a very simple way to use SQLite. Forget parsers, selects, updates! Just .saveData() or .delete() for example.

The Core of solution is the NAMObjectModel class. It abstract all sql commands.

When you initialize the library for the first time, NAMDatabase creates a .sqlite database and all the tables based in classes that implement NAMObjectModel.

How it works

First, create a model:

If you need to persist a property, add @objc.

import NAMDatabase

class Person: NAMObjectModel {
    @objc var name: String!


This code will create the Database and all Tables.

In your AppDelegate add:


Send true to log the Database Path.

If you need recreate the tables run:


This code will drop and recreate the database, be careful.

Saving Data:

let person = Person() = "Narlei"
person.identifier = "MY_ID"

If a register with id == "MY_ID" already exists, will be updated.

To get a unique ID you can use:

let person = Person()
let id = person.getUniqueKey()
person.identifier = id

Retrieving Data:

// Get by Identifier:
if let personResult = Person.getObjectWithId("MY_ID") as? Person {

// Get with SQLite where:
if let array = Person.getAllDataWhere("name like 'Nar%'") as? [Person] {

Delete Data

Delete by Identifier:

Person.deleteObject(withId: "MY_ID")

Delete with SQLite where:

Person.deleteAllDataWhere("name like 'Nar%'")

Ignored Properties

In Swift classes, if you want to ignore properties, just not add @objc or you can use:

override class func ignoredProperties() -> [Any]! {
    return ["name"]

Primary Key

A default property identifier is the primary key, you can change it using:

override class func primaryKeys() -> [Any]! {
	return ["id"]


NAMDatabase is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'NAMDatabase'


To run the example project, clone the repo, and run pod install from the Example directory first.

See the examples here


  • Create template to create Models;
  • Database migration Helper;




NAMDatabase is available under the MIT license. See the LICENSE file for more info.

Pay me a coffee:


You can’t perform that action at this time.