OHMySQL
Swift + MySQL = ❤️
Install / Use
/learn @oleghnidets/OHMySQLREADME
OHMySQL
OHMySQL can connect to remote or local MySQL database and execute CRUD operations. The framework is built upon MySQL C API, but you don’t need to dive into low-level. The following diagram represents a general architecture. Logic (saving, editing, removing etc.) is aggregated in the app. The database is just a shared storage.
<p align="center" >⭐️ <b>Every star is appreciated!</b> ⭐️</p> <!-- @import "[TOC]" {cmd="toc" depthFrom=2 depthTo=6 orderedList=false} --> <!-- code_chunk_output --> <!-- /code_chunk_output -->Features
- [x] Supports Swift and Objective-C
- [x] Requires minimal knowledge in SQL
- [x] Easy to integrate and use
- [x] Many functionality features
- [x] Up-to-date MySQL library
- [x] Documentation and support
Platforms
| Platform | Supported | | ----------- | --------- | | iOS | 14.0+ | | macOS | 11.0+ | | Mac Catalyst| 14.0+ | | watchOS | 8.0+ | | tvOS | 15.0+ |
Project Support
I wish to support the library and extend API and functionality. If you donate me some money 💵, it keeps me motivated and happy 🙂 You may support me via PayPal or let me know any other method convenient for you.
Installation
Read documentation how to install the library as a dependency in your project.
Usage
Connect to the database.
let user = MySQLConfiguration(userName: "root",
password: "root",
serverName: "localhost",
dbName: "dbname",
port: 3306,
socket: "/mysql/mysql.sock")
let coordinator = MySQLStoreCoordinator(user: user!)
coordinator.encoding = .UTF8MB4
coordinator.connect()
To end a connection:
coordinator.disconnect()
Query Context
To execute a query you have to create the context:
let context = MySQLQueryContext()
context.storeCoordinator = coordinator
Execute Query
let dropQueryString = "DROP TABLE `MyTable`"
let dropQueryRequest = MySQLQueryRequest(queryString: dropQueryString)
try? context.execute(dropQueryRequest)
SELECT
The response contains the array of the dictionaries.
let query = MySQLQueryRequestFactory.select("tasks", condition: nil)
let response = try? context.executeQueryRequestAndFetchResult(query)
INSERT
let query = MySQLQueryRequestFactory.insert("tasks", set: ["name": "Something", "description": "new task"])
try? context.execute(query)
UPDATE
let query = MySQLQueryRequestFactory.update("tasks", set: ["name": "Something"], condition: "id=7")
try? context.execute(query)
DELETE
let query = MySQLQueryRequestFactory.delete("tasks", condition: "id=10")
try? context.execute(query)
JOINs
You can execute 4 types of joins - INNER, RIGHT, LEFT, FULL.
let query = MySQLQueryRequestFactory.joinType(OHJoinInner, fromTable: "tasks", columnNames: ["id", "name", "description"], joinOn: ["subtasks": "tasks.id=subtasks.parentId"])
let result = try? context.executeQueryRequestAndFetchResult(query)
Object Mapping
You have to implement the protocol OHMappingProtocol for your models.
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).
context.insertObject(task)
try? context.save()
You can update/delete the objects easily.
let task = Task()
task.name = "sample"
context.updateObject(task)
context.deleteObject(task)
try? context.save()
Communication
- If you found a bug, have a suggestion or need help, open the issue.
- If you want to contribute, submit a pull request.
- If you need help, write me.
License
See LICENSE.
Related Skills
oracle
328.7kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
prose
328.7kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
Command Development
81.0kThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
Plugin Structure
81.0kThis skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
