Description
The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database using OHMySQL API. It allows you doing queries in easy and object-oriented way. Common queries such as SELECT, INSERT, DELETE, JOIN are wrapped by Objective-C code and you donβt need to dive into MySQL C API.
OHMySQL alternatives and similar libraries
Based on the "Database" category.
Alternatively, view OHMySQL alternatives based on common mentions on social networks and blogs.
-
MMKV
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX. -
GRDB.swift
A toolkit for SQLite databases, with a focus on application development -
YapDatabase
YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers. -
ParseAlternatives
GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development. [Moved to: https://github.com/relatedcode/GraphQLite] -
Couchbase Mobile
Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps. -
FCModel
An alternative to Core Data for people who like having direct SQL access. -
UserDefaults
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS -
CTPersistance
iOS Database Persistence Layer with SQLite, your next Persistence Layer! -
Unrealm
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm. -
Prephirences
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults -
RealmIncrementalStore
Realm-powered Core Data persistent store -
ObjectBox
ObjectBox Swift - persisting your Swift objects superfast and simple -
UserDefaultsStore
Why not use UserDefaults to store Codable objects π -
PredicateEditor
A GUI for dynamically creating NSPredicates at runtime to query data in your iOS app. -
Nora
Nora is a Firebase abstraction layer for FirebaseDatabase and FirebaseStorage -
realm-cocoa-converter
A library that provides the ability to import/export Realm files from a variety of data container formats. -
MySQL
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers. -
SecureDefaults
A lightweight wrapper over UserDefaults/NSUserDefaults with an additional layer of AES-256 encryption -
PersistentStorageSerializable
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk. -
PersistenceKit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code! -
YapDatabaseExtensions
YapDatabase extensions for use with Swift -
TypedDefaults
TypedDefaults is a utility library to type-safely use NSUserDefaults. -
MongoDB
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers. -
PostgreSQL
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. -
ObjectiveRocks
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. -
Storez
πΎ Safe, statically-typed, store-agnostic key-value storage written in Swift! -
FileMaker
A stand-alone Swift wrapper around the FileMaker XML Web publishing interface, enabling access to FileMaker servers.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of OHMySQL or a related project?
Popular Comparisons
README
OHMySQL
β β Every star is appreciated! β β
The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database using OHMySQL API. It allows you doing queries in easy and object-oriented way. Common queries such as SELECT, INSERT, DELETE, JOIN are wrapped by Objective-C code and you don't need to dive into MySQL C API.
Goal
If you are interested in and want to know how it can be applied in your project too.
Features
- [x] Easy to integrate and use
- [x] Many functionality features
- [x] Requires minimal knowledge in SQL
- [x] Supports iOS and macOS
- [x] Clean code with unit tests
- [x] Complete documentation and support ## Requirements
- iOS 8.0+ / macOS 10.9+
- Xcode 8.1+
How To Get Started
- To test locally you can install MySQL or MAMP local server.
- Try to use OHMySQL API (set up demo project, read documentation).
- When it'll be ready then transfer your local Data Base(s) to remote MySQL server.
Installation
You can use CocoaPods. Add the following line to your Podfile:
pod 'OHMySQL'
If you are using Swift do not forget to add use_frameworks!
at the top of Podfile. Add platform, example platform :osx, '10.10'
.
Usage
At the first you need to connect to the database.
Objective-C version:
OHMySQLUser *user = [[OHMySQLUser alloc] initWithUserName:@"root"
password:@"root"
serverName:@"localhost"
dbName:@"sample"
port:3306
socket:@"/Applications/MAMP/tmp/mysql/mysql.sock"];
OHMySQLStoreCoordinator *coordinator = [[OHMySQLStoreCoordinator alloc] initWithUser:user];
[coordinator connect];
Swift version:
let user = OHMySQLUser(userName: "root", password: "root", serverName: "localhost", dbName: "ohmysql", port: 3306, socket: "/Applications/MAMP/tmp/mysql/mysql.sock")
let coordinator = OHMySQLStoreCoordinator(user: user!)
coordinator.encoding = .UTF8MB4
coordinator.connect()
To end a connection:
[coordinator disconnect];
coordinator.disconnect()
Query Context
To execute a query you have to create the context:
OHMySQLQueryContext *queryContext = [OHMySQLQueryContext new];
queryContext.storeCoordinator = coordinator;
let context = OHMySQLQueryContext()
context.storeCoordinator = coordinator
You will use this context to execute queries or manipulate the objects.
SELECT
The response contains array of dictionaries (like JSON).
OHMySQLQueryRequest *query = [OHMySQLQueryRequestFactory SELECT:@"tasks" condition:nil];
NSError *error = nil;
NSArray *tasks = [queryContext executeQueryRequestAndFetchResult:query error:&error];
let query = OHMySQLQueryRequestFactory.select("tasks", condition: nil)
let response = try? OHMySQLContainer.shared.mainQueryContext?.executeQueryRequestAndFetchResult(query)
You will get a response like this:
[{ @"id": @1, @"name": @"Task name", @"description": @"Task description", @"status": [NSNull null] }]
INSERT
OHMySQLQueryRequest *query = [OHMySQLQueryRequestFactory INSERT:@"tasks" set:@{ @"name": @"Something", @"desctiption": @"new task" }];
NSError error;
[queryContext executeQueryRequest:query error:&error];
let query = OHMySQLQueryRequestFactory.insert("tasks", set: ["name": "Something", "desctiption": "new task"])
try? mainQueryContext?.execute(query)
UPDATE
OHMySQLQueryRequest *query = [OHMySQLQueryRequestFactory UPDATE:@"tasks" set:@{ @"name": @"Something", @"description": @"new task update" } condition:@"id=5"];
NSError error;
[queryContext executeQueryRequest:query error:&error];
let query = OHMySQLQueryRequestFactory.update("tasks", set: ["name": "Something"], condition: "id=7")
try? mainQueryContext?.execute(query)
DELETE
OHMySQLQueryRequest *query = [OHMySQLQueryRequestFactory DELETE:@"tasks" condition:@"id=10"];
NSError error;
[queryContext executeQueryRequest:query error:&error];
let query = OHMySQLQueryRequestFactory.delete("tasks", condition: "id=10")
try? mainQueryContext?.execute(query)
JOINs
The response contains array of dictionaries (like JSON). You can do 4 types of joins (INNER, RIGHT, LEFT, FULL) using string constants.
OHMySQLQueryRequest *query = [OHMySQLQueryRequestFactory JOINType:OHJoinInner fromTable:@"tasks"
columnNames:@[@"id", @"name", @"description"]
joinOn:@{ @"subtasks":@"tasks.id=subtasks.parentId" }];
NSArray *results = [queryContext executeQueryRequestAndFetchResult:query error:nil];
let query = OHMySQLQueryRequestFactory.joinType(OHJoinInner, fromTable: "tasks", columnNames: ["id", "name", "description"], joinOn: ["subtasks": "tasks.id=subtasks.parentId"])
let result = try? mainQueryContext?.executeQueryRequestAndFetchResult(query)
Object Mapping
You have to implement the protocol OHMappingProtocol for your models. Insertion looks like the following (in this example the NSManagedObject instance). The library has only a primary logic for mapping, so I would recommend you writing a mapping logic by yourself. If you are using Swift you cannot use fundamental number types (Int, Double), only NSNumber (due to run-time).
[queryContext insertObject:task];
BOOL result = [queryContext save:nil];
mainQueryContext?.insertObject(task)
try? mainQueryContext?.save()
You can update/delete the objects easily.
// You don't need to specify primary index here. It'll be update for you.
OHTask *task = [OHTask new];
task.name = @"Code cleanup";
task.taskDescription = @"Delete unused classes and files";
task.status = 0;
[queryContext updateObject:task];
...
task.name = @"Something";
task.status = 1;
[task update];
...
[queryContext deleteObject:task];
BOOL result = [queryContext save:nil];
let task = Task()
task.name = "sample"
mainQueryContext?.updateObject(task)
mainQueryContext?.deleteObject(task)
try? mainQueryContext?.save()
Communication
- If you found a bug, have suggestions or need help, please, open an issue.
- If you want to contribute, submit a pull request.
- If you need help, write me [email protected].
- Make me feel happier ;]
License
OHMySQL is released under the MIT license. See [LICENSE](LICENSE) for details.
*Note that all licence references and agreements mentioned in the OHMySQL README section above
are relevant to that project's source code only.