Giter Site home page Giter Site logo

dkdbmanager's Introduction

DKDBManager

Build Status codecov.io Cocoapods Carthage compatible License Platform

Concept

DKDBManager is a simple, yet very useful, CRUD manager around Magical Record.

It implements a logic around the database that helps the developer to manage his entities and let him focus on other things than only data management.

The main concept is to import JSON dictionaries representing entities into the database.

After some configuration on your model classes, only one single function is needed to create, read, update or delete your entities!

Documentation

The complete documentation is available on CocoaDocs.

More over, the Wiki contains all kind of information and details about the different logics of the library.

Quick overview

With the DKDBManager and MagicalRecord you can easily create, update or delete entities.

To do so you need to be in a savingContext and use the appropriate DKDBManager functions:

DKDBManager.saveWithBlock { (savingContext: NSManagedObjectContext) in

    // Perform saving code here, against the `savingContext` instance.
    // Everything done in this block will occur on a background thread.

	let plane = Plane.crudEntityInContext(savingContext)
	plane?.origin = "London"
    plane?.destination = "Paris"
}

At the end of this execution block, all changes will be saved ( or merged ) into the default context.

After that, a new Plane entity will be available on the main thread within the default context.

Or you could CRUD an entity by using a JSON structure:

let planeJSON = ["origin":"Paris", "destination":"London"]
Plane.crudEntityWithDictionary(planeJSON, inContext: savingContext, completion: { (entity: AnyObject?, state: DKDBManagedObjectState) in

	// The CRUDed plane is referenced in the `entity`.
	// Its actual state is described as follow:
	switch state {
	case .Create:	// The entity has been created, it's all fresh new.
	case .Update:	// The entity has been updated, its attributes changed.
	case .Save:		// The entity has been saved, nothing happened.
	case .Delete:	// The entity has been removed.
	}
})

The state variable describes what happened to the entity.

The implementation of other functions is also recommended such as the one to update the current entity with a given dictionary.

Without this function the attributes of the entity will never be set nor updated.

The given dictionary object is the same one that has been used to start the CRUD process.

override func updateWithDictionary(dictionary: [NSObject : AnyObject]?, inContext savingContext: NSManagedObjectContext) {
	super.updateWithDictionary(dictionary, inContext: savingContext)
	// Update attributes
	self.origin 		= GET_STRING(dictionary, "origin")
	self.destination 	= GET_STRING(dictionary, "destination")
}

Read more in the Wiki! :bowtie:

Try it out!

Checkout the example project:

$> pod try DKDBManager

Author

kevindelord, [email protected]

dkdbmanager's People

Contributors

dirke avatar kevindelord avatar panajotismaroungas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.