{"id":13804721,"url":"https://github.com/mysql-d/mysql-native","last_synced_at":"2025-05-13T18:32:46.887Z","repository":{"id":3146672,"uuid":"4176168","full_name":"mysql-d/mysql-native","owner":"mysql-d","description":"Native D client driver for MySQL/MariaDB, works with or without Vibe.d","archived":false,"fork":true,"pushed_at":"2024-01-10T00:06:56.000Z","size":2314,"stargazers_count":82,"open_issues_count":41,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-13T13:14:45.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/mysql-d/mysql-native","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"simendsjo/mysqln","license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mysql-d.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-04-29T17:46:09.000Z","updated_at":"2025-03-26T11:51:37.000Z","dependencies_parsed_at":"2023-07-05T18:32:30.492Z","dependency_job_id":null,"html_url":"https://github.com/mysql-d/mysql-native","commit_stats":null,"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-d%2Fmysql-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-d%2Fmysql-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-d%2Fmysql-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-d%2Fmysql-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysql-d","download_url":"https://codeload.github.com/mysql-d/mysql-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254003443,"owners_count":21997887,"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":[],"created_at":"2024-08-04T01:00:53.213Z","updated_at":"2025-05-13T18:32:46.269Z","avatar_url":"https://github.com/mysql-d.png","language":"D","funding_links":[],"categories":["Database clients"],"sub_categories":["XML"],"readme":"MySQL native\n============\n\n[![DUB Package](https://img.shields.io/dub/v/mysql-native.svg)](https://code.dlang.org/packages/mysql-native)\n[![GitHub - Builds](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml)\n[![GitHub - Integration Tests](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml)\n\n*NOTE: we are in the process of migrating to github actions. Documentation is now\nbeing generated using github actions, and stored on github. This README\nis in flux at the moment, and may contain outdated information*\n\nA [Boost-licensed](http://www.boost.org/LICENSE_1_0.txt) native [D](http://dlang.org)\nclient driver for MySQL and MariaDB.\n\nThis package attempts to provide composite objects and methods that will\nallow a wide range of common database operations, but be relatively easy to\nuse. It has no dependencies on GPL header files or libraries, instead communicating\ndirectly with the server via the\n[published client/server protocol](http://dev.mysql.com/doc/internals/en/client-server-protocol.html).\n\nThis package supports both [Phobos sockets](https://dlang.org/phobos/std_socket.html)\nand [Vibe.d](http://vibed.org/) sockets. It will automatically use the correct\ntype based on whether Vibe.d is used in your project. (If you use\n[DUB](http://code.dlang.org/getting_started), this is completely seamless.\nOtherwise, you can use `-version=Have_vibe_d_core` to force Vibe.d sockets\ninstead of Phobos ones.)\n\nShould work on D compilers from 2.068 through to the latest release but the CI only tests against version 2.085.1 and above. For a full list see the builds on Github Actions. Note that dub from prior to 2.085.0 will not work, but this is not an issue with mysql-native. To build with prior compilers, use a newer version of dub.\n\nIn this document:\n* [API](#api)\n* [Basic example](#basic-example)\n* [Additional notes](#additional-notes)\n* [Developers - How to run the test suite](#developers---how-to-run-the-test-suite)\n\nSee also:\n* [API Reference](https://mysql-d.github.io/mysql-native/)\n\nAPI\n---\n\n*NOTE: the most recent release of mysql-native has been updated to be usable from `@safe` code, using the `mysql.safe` package. Please see the [safe migration document](SAFE_MIGRATION.md) for more details*\n\n[API Reference](https://mysql-d.github.io/mysql-native/)\n\nThe primary interfaces (all these are the safe versions):\n- [Connection](https://mysql-d.github.io/mysql-native/mysql/impl/connection/Connection.html): Connection to the server, and querying and setting of server parameters.\n- [MySQLPool](https://mysql-d.github.io/mysql-native/mysql/impl/pool/MySQLPoolImpl.html): Connection pool, for Vibe.d users.\n- [exec()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/exec.html): Plain old SQL statement that does NOT return rows (like INSERT/UPDATE/CREATE/etc), returns number of rows affected\n- [query()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/query.html): Execute an SQL statement that DOES return rows (ie, SELECT) and handle the rows one at a time, as an input range.\n- [queryRow()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/queryRow.html): Execute an SQL statement and get the first row.\n- [queryValue()](https://mysql-d.github.io/mysql-native/mysql/safe/commands/queryValue.html): Execute an SQL statement and get the first value in the first row.\n- [prepare()](https://mysql-d.github.io/mysql-native/mysql/safe/connection/prepare.html): Create a prepared statement\n- [Prepared](https://mysql-d.github.io/mysql-native/mysql/impl/prepared/SafePrepared.html): A prepared statement, optionally pass it to the exec/query function in place of an SQL string.\n- [Row](https://mysql-d.github.io/mysql-native/mysql/impl/result/SafeRow.html): One \"row\" of results, used much like an array of Variant.\n- [ResultRange](https://mysql-d.github.io/mysql-native/mysql/impl/result/SafeResultRange.html): An input range of rows. Convert to random access with [std.array.array()](https://dlang.org/phobos/std_array.html#.array).\n\nAlso note the [MySQL \u003c-\u003e D type mappings tables](https://mysql-d.github.io/mysql-native/mysql.html)\n\nBasic example\n-------------\n```d\nimport std.array : array;\nimport mysql.safe; // Please use the safe api, it's the future\n\nvoid main(string[] args)\n{\n\t// Connect\n\tauto connectionStr = \"host=localhost;port=3306;user=yourname;pwd=pass123;db=mysqln_testdb\";\n\tif(args.length \u003e 1)\n\t\tconnectionStr = args[1];\n\tConnection conn = new Connection(connectionStr);\n\tscope(exit) conn.close();\n\n\t// Insert\n\tulong rowsAffected = conn.exec(\n\t\t\"INSERT INTO `tablename` (`id`, `name`) VALUES (1, 'Ann'), (2, 'Bob')\");\n\n\t// Query\n\tResultRange range = conn.query(\"SELECT * FROM `tablename`\");\n\tRow row = range.front;\n\tMySQLVal id = row[0];\n\tMySQLVal name = row[1];\n\tassert(id == 1);\n\tassert(name == \"Ann\");\n\n\trange.popFront();\n\tassert(range.front[0] == 2);\n\tassert(range.front[1] == \"Bob\");\n\n\t// Simplified prepared statements\n\tResultRange bobs = conn.query(\n\t\t\"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?\",\n\t\t\"Bob\", \"Bobby\");\n\tbobs.close(); // Skip them\n\n\tRow[] rs = conn.query( // Same SQL as above, but only prepared once and is reused!\n\t\t\"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?\",\n\t\t\"Bob\", \"Ann\").array; // Get ALL the rows at once\n\tassert(rs.length == 2);\n\tassert(rs[0][0] == 1);\n\tassert(rs[0][1] == \"Ann\");\n\tassert(rs[1][0] == 2);\n\tassert(rs[1][1] == \"Bob\");\n\n\t// Full-featured prepared statements\n\tPrepared prepared = conn.prepare(\"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?\");\n\tprepared.setArgs(\"Bob\", \"Bobby\");\n\tbobs = conn.query(prepared);\n\tbobs.close(); // Skip them\n\n\t// Nulls\n\tconn.exec(\n\t\t\"INSERT INTO `tablename` (`id`, `name`) VALUES (?,?)\",\n\t\tnull, \"Cam\"); // Can also take Nullable!T\n\trange = conn.query(\"SELECT * FROM `tablename` WHERE `name`='Cam'\");\n\tassert( range.front[0].kind == MySQLVal.Kind.Null );\n}\n```\n\nAdditional notes\n----------------\n\nThis requires MySQL server v4.1.1 or later, or a MariaDB server. Older\nversions of MySQL server are obsolete, use known-insecure authentication,\nand are not supported by this package. Currently the github actions tests use\nMySQL 5.7 and MariaDB 10. MySQL 8 is supported with `mysql_native_password`\nauthentication, but is not currently tested. Expect this to change in the future.\n\nNormally, MySQL clients connect to a server on the same machine via a Unix\nsocket on *nix systems, and through a named pipe on Windows. Neither of these\nconventions is currently supported. TCP is used for all connections.\n\nUnfortunately, the original home page of Steve Teale's mysqln is no longer\navailable. You can see an archive on the [Internet Archive wayback\nmachine](https://web.archive.org/web/20120323165808/http://britseyeview.com/software/mysqln)\n\nDevelopers - How to run the test suite\n--------------------------------------\n\nUnittests that do not require an actual server are located in the library\ncodebase. You can run just these tests using `dub test`.\n\nUnittests that require a working server are all located in the\n[integration-tests](integration-tests) subpackage. Due to a [dub\nissue](https://github.com/dlang/dub/issues/2136), the integration tests are run\nusing the [integration-tests-phobos](integration-tests-phobos) and\n[integration-tests-vibe](integration-tests-vibe) subpackages. At some point, if this dub issue\nis fixed, they will simply become configurations in the main integration-tests\nrepository. You can run these directly from the main repository folder by\nissuing the commands:\n\n```sh\ndub run :integration-tests-phobos\ndub run :integration-tests-vibe\n```\nThis will also run the library tests as well as the integration tests.\n\nThe first time you run an integration test, the file `testConnectionStr.txt`\nwill be created in your current directory\n\nOpen the `testConnectionStr.txt` file and verify the connection settings\ninside, modifying them as needed, and if necessary, creating a test user and\nblank test schema in your MySQL database.\n\nThe tests will completely clobber anything inside the db schema provided,\nbut they will ONLY modify that one db schema. No other schema will be\nmodified in any way.\n\nAfter you've configured the connection string, run the integration tests again.\n\nThe integration tests use\n[unit-threaded](https://code.dlang.org/packages/unit-threaded) which allows for\nrunning individual named tests. Use this for running specific tests instead of\nthe whole suite.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysql-d%2Fmysql-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysql-d%2Fmysql-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysql-d%2Fmysql-native/lists"}