{"id":13468249,"url":"https://github.com/vapor/mysql-kit","last_synced_at":"2025-06-16T04:15:25.557Z","repository":{"id":40344234,"uuid":"61243102","full_name":"vapor/mysql-kit","owner":"vapor","description":"🐬 Pure Swift MySQL client built on non-blocking, event-driven sockets.","archived":false,"fork":false,"pushed_at":"2024-05-29T18:20:46.000Z","size":869,"stargazers_count":223,"open_issues_count":5,"forks_count":75,"subscribers_count":23,"default_branch":"main","last_synced_at":"2024-10-29T22:55:59.562Z","etag":null,"topics":["mysql","server-side-swift","swift","swift-linux","vapor","vapor-service"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vapor.png","metadata":{"funding":{"github":["vapor"],"open_collective":"vapor"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-15T21:44:36.000Z","updated_at":"2024-10-16T12:24:28.000Z","dependencies_parsed_at":"2024-05-02T12:31:15.705Z","dependency_job_id":null,"html_url":"https://github.com/vapor/mysql-kit","commit_stats":{"total_commits":489,"total_committers":52,"mean_commits":9.403846153846153,"dds":0.5378323108384457,"last_synced_commit":"6245a07310c4f0ece2355de43108bd8c068c229a"},"previous_names":["vapor/mysql"],"tags_count":116,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fmysql-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fmysql-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fmysql-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor%2Fmysql-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vapor","download_url":"https://codeload.github.com/vapor/mysql-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245267511,"owners_count":20587458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql","server-side-swift","swift","swift-linux","vapor","vapor-service"],"created_at":"2024-07-31T15:01:07.601Z","updated_at":"2025-06-16T04:15:25.541Z","avatar_url":"https://github.com/vapor.png","language":"Swift","funding_links":["https://github.com/sponsors/vapor","https://opencollective.com/vapor"],"categories":["Swift"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://design.vapor.codes/images/vapor-mysqlkit.svg\" height=\"96\" alt=\"MySQLKit\"\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\u003ca href=\"https://docs.vapor.codes/4.0/\"\u003e\u003cimg src=\"https://design.vapor.codes/images/readthedocs.svg\" alt=\"Documentation\"\u003e\u003c/a\u003e\n\u003ca href=\"https://discord.gg/vapor\"\u003e\u003cimg src=\"https://design.vapor.codes/images/discordchat.svg\" alt=\"Team Chat\"\u003e\u003c/a\u003e\n\u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://design.vapor.codes/images/mitlicense.svg\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/vapor/mysql-kit/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/vapor/mysql-kit/test.yml?event=push\u0026style=plastic\u0026logo=github\u0026label=tests\u0026logoColor=%23ccc\" alt=\"Continuous Integration\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/github/vapor/mysql-kit\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/vapor/mysql-kit?style=plastic\u0026logo=codecov\u0026label=codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://swift.org\"\u003e\u003cimg src=\"https://design.vapor.codes/images/swift510up.svg\" alt=\"Swift 5.10+\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\nMySQLKit is an [SQLKit] driver for MySQL clients. It supports building and serializing MySQL-dialect SQL queries. MySQLKit uses [MySQLNIO] to connect and communicate with the database server asynchronously. [AsyncKit] is used to provide connection pooling.\n\n[SQLKit]: https://github.com/vapor/sql-kit\n[MySQLNIO]: https://github.com/vapor/mysql-nio\n[AsyncKit]: https://github.com/vapor/async-kit\n\n### Usage\n\nUse the SPM string to easily include the dependendency in your `Package.swift` file.\n\n```swift\n.package(url: \"https://github.com/vapor/mysql-kit.git\", from: \"4.0.0\")\n```\n\n### Supported Platforms\n\nMySQLKit supports the following platforms:\n\n- Ubuntu 20.04+\n- macOS 10.15+\n\n### Configuration\n\nDatabase connection options and credentials are specified using a `MySQLConfiguration` struct. \n\n```swift\nimport MySQLKit\n\nlet configuration = MySQLConfiguration(\n    hostname: \"localhost\",\n    port: 3306,\n    username: \"vapor_username\",\n    password: \"vapor_password\",\n    database: \"vapor_database\"\n)\n```\n\nURL string based configuration is also supported.\n\n```swift\nguard let configuration = MySQLConfiguration(url: \"mysql://...\") else {\n    ...\n}\n```\n\nTo connect via unix-domain sockets, use `unixDomainSocketPath` instead of `hostname` and `port`.\n\n```swift\nlet configuration = MySQLConfiguration(\n    unixDomainSocketPath: \"/path/to/socket\",\n    username: \"vapor_username\",\n    password: \"vapor_password\",\n    database: \"vapor_database\"\n)\n```\n\n### Connection Pool\n\nOnce you have a `MySQLConfiguration`, you can use it to create a connection source and pool.\n\n```swift\nlet eventLoopGroup: EventLoopGroup = ...\ndefer { try! eventLoopGroup.syncShutdown() }\n\nlet pools = EventLoopGroupConnectionPool(\n    source: MySQLConnectionSource(configuration: configuration), \n    on: eventLoopGroup\n)\ndefer { pools.shutdown() }\n```\n\nFirst create a `MySQLConnectionSource` using the configuration struct. This type is responsible for creating new connections to your database server as needed.\n\nNext, use the connection source to create an `EventLoopGroupConnectionPool`. You will also need to pass an `EventLoopGroup`. For more information on creating an `EventLoopGroup`, visit SwiftNIO's [documentation](https://apple.github.io/swift-nio/docs/current/NIO/index.html). Make sure to shutdown the connection pool before it deinitializes. \n\n`EventLoopGroupConnectionPool` is a collection of pools for each event loop. When using `EventLoopGroupConnectionPool` directly, random event loops will be chosen as needed.\n\n```swift\npools.withConnection { conn \n    print(conn) // MySQLConnection on randomly chosen event loop\n}\n```\n\nTo get a pool for a specific event loop, use `pool(for:)`. This returns an `EventLoopConnectionPool`. \n\n```swift\nlet eventLoop: EventLoop = ...\nlet pool = pools.pool(for: eventLoop)\n\npool.withConnection { conn\n    print(conn) // MySQLConnection on eventLoop\n}\n```\n\n### MySQLDatabase\n\nBoth `EventLoopGroupConnectionPool` and `EventLoopConnectionPool` can be used to create instances of `MySQLDatabase`.\n\n```swift\nlet mysql = pool.database(logger: ...) // MySQLDatabase\nlet rows = try mysql.simpleQuery(\"SELECT @@version;\").wait()\n```\n\nVisit [MySQLNIO's docs](https://github.com/vapor/mysql-nio) for more information on using `MySQLDatabase`.\n\n### SQLDatabase\n\nA `MySQLDatabase` can be used to create an instance of `SQLDatabase`.\n\n```swift\nlet sql = mysql.sql() // SQLDatabase\nlet planets = try sql.select().column(\"*\").from(\"planets\").all().wait()\n```\n\nVisit [SQLKit's docs](https://api.vapor.codes/sqlkit/documentation/sqlkit) for more information on using `SQLDatabase`. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor%2Fmysql-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvapor%2Fmysql-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor%2Fmysql-kit/lists"}