All Projects → oleghnidets → Ohmysql

oleghnidets / Ohmysql

Licence: mit
Easy direct access to your database 🎯 http://oleghnidets.github.io/OHMySQL/

Programming Languages

c
50402 projects - #5 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to Ohmysql

Event Management
helps to register an users for on events conducted in college fests with simple logic with secured way
Stars: ✭ 65 (-60.84%)
Mutual labels:  sql, database, mysql, dbms
Qtl
A friendly and lightweight C++ database library for MySQL, PostgreSQL, SQLite and ODBC.
Stars: ✭ 92 (-44.58%)
Mutual labels:  sql, database, mysql
Querybuilder
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
Stars: ✭ 2,111 (+1171.69%)
Mutual labels:  sql, database, mysql
Myproxy
A sharding proxy for MYSQL databases
Stars: ✭ 153 (-7.83%)
Mutual labels:  sql, database, mysql
Laravel Log To Db
Custom Laravel and Lumen 5.6+ Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel/Monolog native logging functionality.
Stars: ✭ 76 (-54.22%)
Mutual labels:  sql, database, mysql
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+661.45%)
Mutual labels:  sql, database, mysql
Alpine Mariadb
MariaDB running on Alpine Linux [Docker]
Stars: ✭ 117 (-29.52%)
Mutual labels:  sql, database, mysql
Dolt
Dolt – It's Git for Data
Stars: ✭ 9,880 (+5851.81%)
Mutual labels:  sql, database, mysql
Online Shopping System Advanced
Demo site
Stars: ✭ 127 (-23.49%)
Mutual labels:  database, mysql, dbms
Kangaroo
SQL client and admin tool for popular databases
Stars: ✭ 127 (-23.49%)
Mutual labels:  sql, database, mysql
Db Tutorial
💾 db-tutorial 是一个数据库教程。
Stars: ✭ 128 (-22.89%)
Mutual labels:  sql, database, mysql
Ebean
Ebean ORM
Stars: ✭ 1,172 (+606.02%)
Mutual labels:  sql, database, mysql
Directus Docker
Directus 6 Docker — Legacy Container [EOL]
Stars: ✭ 68 (-59.04%)
Mutual labels:  sql, database, mysql
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+663.25%)
Mutual labels:  sql, database, mysql
Mysql
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
Stars: ✭ 11,735 (+6969.28%)
Mutual labels:  sql, database, mysql
Node Mysql Utilities
Query builder for node-mysql with introspection, etc.
Stars: ✭ 98 (-40.96%)
Mutual labels:  sql, database, mysql
Mysqldump Php
PHP version of mysqldump cli that comes with MySQL
Stars: ✭ 975 (+487.35%)
Mutual labels:  sql, database, mysql
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+492.77%)
Mutual labels:  sql, database, mysql
Mysql Container
MySQL container images based on Red Hat Software Collections and intended for OpenShift and general usage. Users can choose between Red Hat Enterprise Linux, Fedora, and CentOS based images.
Stars: ✭ 117 (-29.52%)
Mutual labels:  sql, database, mysql
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+1172.29%)
Mutual labels:  sql, database, mysql

OHMySQL

License License Documentation

★★ 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

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

paypal

License

OHMySQL is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].