Easiest local storage library in Swift

Overview

Sundeed

SundeedQLite

Build Status codecov.io CocoaPods Compatible Platform License Language Last Commit

SundeedQLite is the easiest offline database integration, built using Swift language

Requirements

  • iOS 12.0+
  • XCode 10.3+
  • Swift 5+

Installation


Installation via CocoaPods

SundeedQLite is available through CocoaPods. CocoaPods is a dependency manager that automates and simplifies the process of using 3rd-party libraries like MarkdownKit in your projects. You can install CocoaPods with the following command:

gem install cocoapods

To integrate SundeedQLite into your Xcode project using CocoaPods, simply add the following line to your Podfile:

pod "SundeedQLite"

Afterwards, run the following command:

pod install

Signs

  • + : It's used to mark the primary key in the database.
  • << : It's used to mark the ASCENDING sorting method
  • >> : It's used to mark the DESCENDING sorting method
  • <~> : It's used to map between objects returned from the database to specific property
  • <*> : It's used to state that if this property is returned nil from the database, the whole parent object shall be dropped.
  • <**> : It's used to state that if this array was empty, or one of the elements was mandatory ( <*> ), the whole parent object shall be dropped

N.B:

  • Primary keys should always be strings.
  • To create a nested object (e.g: Employee), both Employer and Employee should have primary keys.

Supported Types

  • SundeedQLiter Objects
  • String
  • Int
  • Double
  • Float
  • Bool
  • Date
  • UIImage
  • Array
  • enum/struct (see below documentation)

P.S:

  • Nested objects will be normally saved
  • Optional and non-optional values of the above mentioned types will also be saved
  • Arrays of objects or primitive data type will be saved
  • No nil returned value from the database shall be added to an array while retrieving

Listeners

To Listen to events happening you can always add any listener with a block of code to be executed when the event happens.

Supported Events

  • Save
  • Update
  • Retrieve
  • Delete
  • AllEvents

P.S: Always remember to save an instance of this listener to stop it whenever it's not needed anymore.

Documentation

import SundeedQLite

class Employer: SundeedQLiter {
    var id: String!
    var fullName: String?
    var employees: [Employee]?

    required init() {}
        func sundeedQLiterMapping(map: SundeedQLiteMap) {
            id <~> map["id"]+
            fullName <~> map["fullName"]<<
            employees <~> map["employees"]
        }
    }
class Employee: SundeedQLiter {
    var id: String!
    var firstName: String?
    required init() {}
    func sundeedQLiterMapping(map: SundeedQLiteMap) {
        id <~> map["id"]
        firstName <~> map["firstName"]
    }
}
import UIKit

class ViewController: UIViewController {
    var employerSaveListener: Listener?
    override func viewDidLoad() {
        super.viewDidLoad()
        let employee = Employee()
        employee.firstName = "Nour"

        let employer = Employer()
        employer.id = "ABCD-1234-EFGH-5678"
        employer.fullName = "Nour Sandid"
        employer.employees = [employee]
        employerSaveListener = employer.onSaveEvents({ (object) in 
            print(object.id)
        })
        employer.save()
    }
    
    deinit {
        employerSaveListener.stop()
    }
}

Custom Types

To save variables with custom types like enum or struct, you can use SundeedQLiteConverter

class TypeConverter: SundeedQLiteConverter {
    func fromString(value: String) -> Any? {
       return Type(rawValue: value)
    }
    func toString(value: Any?) -> String? {
        return (value as? Type)?.rawValue
    }
}

enum Type: String {
    case manager
    case ceo
}

class Employer: SundeedQLiter {
    var type: Type?
    
    func sundeedQLiterMapping(map: SundeedQLiteMap) {
        type <~> (map["type"], TypeConverter())
    }
}

CheatSheet

To Save

employer.save()

To Retrieve

Employer.retrieve { (employers) in
    for employer in employers {
        print(employer.fullName)
    }
}

Employer.retrieve(withFilter: SundeedColumn("fullName") == "Nour Sandid",
                  orderBy: SundeedColumn("fullName"),
                  ascending: true) { (employers) in
    for employer in employers {
        print(employer.fullName)
    }
}

To Reset The Database

SundeedQLite.deleteDatabase()

Built Using

SQLite3

License

MIT

You might also like...
Web server serving local files

swift-web A web server serving local static files. Installation Using Mint The easiest way to install swift-web is via mint. mint install adam-fowler/

rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps.
rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps.

rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps. Trackers can use a va

🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

🧡 Easy to use SQLite ORM library written with Swift

A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

Elegant library to manage the interactions between view and model in Swift
Elegant library to manage the interactions between view and model in Swift

An assistant to manage the interactions between view and model ModelAssistant is a mediator between the view and model. This framework is tailored to

Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults

Prephirences - Preϕrences Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, co

A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.

Perfect - MySQL Connector This project provides a Swift wrapper around the MySQL client library, enabling access to MySQL database servers. This packa

A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Perfect - PostgreSQL Connector This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. This pack

Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.

PersistentStorageSerializable PersistentStorageSerializable is a protocol for automatic serialization and deserialization of Swift class, struct or NS

Comments
  • Retrive function - nil variable value

    Retrive function - nil variable value

    First of all thank you for your amazing work. It is very easy to use.

    I'm facing some strange errors when I try to use the .retrive function.

    This is the console output:

    2019-10-22 19:19:48.639081+0200 App[991:726609] [logging-persist] cannot open file at line 43348 of [378230ae7f]
    2019-10-22 19:19:48.639134+0200 App[991:726609] [logging-persist] os_unix.c:43348: (0) open(/var/mobile/Containers/Data/Application/0E18469B-5BB9-46A6-9567-DCEC9DD4D179/Documents/SQLiteDB.sqlite) - Undefined error: 0
    

    The app still works and the retrive function gives back the result but some variables of the objects are nil.

    opened by FIndustries 5
  • Fixed image saving

    Fixed image saving

    • Bug in image saving that prevented the user to be able to save two images for the same object
    • Added more images for tests
    • Fixed tests for images
    • Bug in statements that produces an error if no update happened
    opened by noursandid 0
Owner
Nour Sandid
Nour Sandid
StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage

StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage. Requirements iOS 8.0+ / macOS 10.10+ / tvOS

Amr Salman 47 Nov 3, 2022
pick the voice from the local storage.you can play and pause the voice

flutter_add_voice A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

Mehrab Bozorgi 1 Nov 27, 2021
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Saoud Rizwan 3k Jan 3, 2023
💾 Safe, statically-typed, store-agnostic key-value storage written in Swift!

Storez ?? Safe, statically-typed, store-agnostic key-value storage Highlights Fully Customizable: Customize the persistence store, the KeyType class,

Kitz 67 Aug 7, 2022
🛶Shallows is a generic abstraction layer over lightweight data storage and persistence.

Shallows Shallows is a generic abstraction layer over lightweight data storage and persistence. It provides a Storage<Key, Value> type, instances of w

Oleg Dreyman 620 Dec 3, 2022
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage.

ObjectiveRocks ObjectiveRocks is an Objective-C wrapper of Facebook's RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. Current RocksD

Iskandar Abudiab 56 Nov 5, 2022
Your Data Storage Troubleshooter 🛠

Your Data Storage Troubleshooter ?? Introduction StorageKit is a framework which reduces the complexity of managing a persistent layer. You can easily

StorageKit 231 Dec 29, 2022
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.

中文版本请参看这里 MMKV is an efficient, small, easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available on Andr

Tencent 15.4k Jan 6, 2023
An elegant, fast, thread-safe, multipurpose key-value storage, compatible with all Apple platforms.

KeyValueStorage An elegant, fast, thread-safe, multipurpose key-value storage, compatible with all Apple platforms. Supported Platforms iOS macOS watc

null 3 Aug 21, 2022
Typed key-value storage solution to store Codable types in various persistence layers with few lines of code!

?? Stores A typed key-value storage solution to store Codable types in various persistence layers like User Defaults, File System, Core Data, Keychain

Omar Albeik 94 Dec 31, 2022