NAMDatabase 1.0.6

NAMDatabase 1.0.6

Maintained by Narlei Moreira.


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 carrefully.

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;


narlei, [email protected]


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

Pay me a coffee: