{"id":13792542,"url":"https://github.com/tarantool/mysql","last_synced_at":"2025-04-14T15:10:55.399Z","repository":{"id":31166053,"uuid":"34726223","full_name":"tarantool/mysql","owner":"tarantool","description":"MySQL connector for Tarantool","archived":false,"fork":false,"pushed_at":"2024-07-12T08:48:22.000Z","size":3953,"stargazers_count":19,"open_issues_count":14,"forks_count":7,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-03-28T04:03:27.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarantool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-28T11:19:27.000Z","updated_at":"2024-11-15T23:00:07.000Z","dependencies_parsed_at":"2024-07-12T10:05:46.276Z","dependency_job_id":"ee0c9b5b-3209-4e00-bf80-3ee7e8e486cb","html_url":"https://github.com/tarantool/mysql","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fmysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fmysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fmysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fmysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarantool","download_url":"https://codeload.github.com/tarantool/mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904640,"owners_count":21180835,"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-03T22:01:13.488Z","updated_at":"2025-04-14T15:10:55.355Z","avatar_url":"https://github.com/tarantool.png","language":"Lua","funding_links":[],"categories":["Packages"],"sub_categories":["Clients"],"readme":"# mysql - MySQL connector for [Tarantool][]\n\n[![fast-testing status][testing-actions-badge]][testing-actions-url]\n[![publish status][publish-actions-badge]][publish-actions-url]\n\n## Getting Started\n\n### Prerequisites\n\n* Tarantool 1.6.5+ with header files (tarantool \u0026\u0026 tarantool-dev /\n  tarantool-devel packages).\n* MySQL 5.1 header files (libmysqlclient-dev package).\n* OpenSSL development package.\n* libucontext (only for Alpine).\n\nIf you prefer to install the connector using a system package manager you don't\nneed to manually install dependencies.\n\n### Installation\n\n#### Build from sources\n\nClone repository and then build it using CMake:\n\n```sh\ngit clone https://github.com/tarantool/mysql.git tarantool-mysql\ncd tarantool-mysql \u0026\u0026 cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo\nmake\nmake install\n```\n\n#### Run tests\n\nTo run the tests, the following preparatory steps must be completed:\n* Run mysql instance.\n* Connect a client to the instance and execute the commands:\n  * `CREATE USER 'test_user' IDENTIFIED WITH mysql_native_password BY 'pass';`\n  * `CREATE DATABASE tarantool_mysql_test;`\n  * `GRANT ALL PRIVILEGES ON *.* TO 'test_user';`\n* Define MYSQL environment variable using the following format:\u003cbr/\u003e\n`ip:port:user:user_pass:db_name:`\u003cbr/\u003e\nExample:\u003cbr/\u003e\n`export MYSQL=127.0.0.1:3306:test_user:pass:tarantool_mysql_test:`\n\nThe tests can now be run by `make check`.\n\n#### tt rocks\n\nYou can also use `tt rocks`:\n\n```sh\ntt rocks install mysql\n```\n\n#### Install a package\n\n[Enable tarantool repository][tarantool_download] and install tarantool-mysql\npackage:\n\n```sh\napt-get install tarantool-mysql # Debian or Ubuntu\nyum install tarantool-mysql     # CentOS\ndnf install tarantool-mysql     # Fedora\n```\n\n[tarantool_download]: https://www.tarantool.io/en/download/\n\n### Usage\n\n``` lua\nlocal mysql = require('mysql')\nlocal pool = mysql.pool_create({ host = '127.0.0.1', user = 'user', password = 'password', db = 'db', size = 5 })\nlocal conn = pool:get()\nlocal tuples, status  = conn:execute(\"SELECT ? AS a, 'xx' AS b, NULL as c\", 42))\nconn:begin()\nconn:execute(\"INSERT INTO test VALUES(1, 2, 3)\")\nconn:commit()\npool:put(conn)\n```\n\n## API Documentation\n\n### `conn = mysql.connect(opts)`\n\nConnect to a database.\n\n*Options*:\n\n - `host` - hostname to connect to\n - `port` - port number to connect to\n - `user` - username\n - `password` - password\n - `db` - database name\n - `use_numeric_result` - provide result of the \"conn:execute\" as ordered list\n   (true/false); default value: false\n - `keep_null` - provide printing null fields in the result of the\n   \"conn:execute\" (true/false); default value: false\n\nThrows an error on failure.\n\n*Returns*:\n\n - `connection ~= nil` on success\n\n### `conn:execute(statement, ...)`\n\nExecute a statement with arguments in the current transaction.\n\nThrows an error on failure.\n\n*Returns*:\n\n - `results, true` on success, where `results` is in the following form:\n\n(when `use_numeric_result = false` or is not set on a pool/connection creation)\n\n```lua\n{\n    { -- result set\n        {column1 = r1c1val, column2 = r1c2val, ...}, -- row\n        {column1 = r2c1val, column2 = r2c2val, ...}, -- row\n        ...\n    },\n    ...\n}\n```\n\n(when `use_numeric_result = true` on a pool/connection creation)\n\n```lua\n{\n    { -- result set\n        rows = {\n            {r1c1val, r1c2val, ...}, -- row\n            {r2c1val, r2c2val, ...}, -- row\n            ...\n        },\n        metadata = {\n            {type = 'long', name = 'col1'}, -- column meta\n            {type = 'long', name = 'col2'}, -- column meta\n            ...\n        },\n    },\n    ...\n}\n```\n\n*Example*:\n\n(when `keep_null = false` or is not set on a pool/connection creation)\n\n```\ntarantool\u003e conn:execute(\"SELECT ? AS a, 'xx' AS b\", NULL AS c , 42)\n---\n- - - a: 42\n      b: xx\n- true\n...\n```\n\n(when `keep_null = true` on a pool/connection creation)\n\n```\ntarantool\u003e conn:execute(\"SELECT ? AS a, 'xx' AS b\", NULL AS c, 42)\n---\n- - - a: 42\n      b: xx\n      c: null\n- true\n...\n```\n\n### `conn:begin()`\n\nBegin a transaction.\n\n*Returns*: `true`\n\n### `conn:commit()`\n\nCommit current transaction.\n\n*Returns*: `true`\n\n### `conn:rollback()`\n\nRollback current transaction.\n\n*Returns*: `true`\n\n### `conn:ping()`\n\nExecute a dummy statement to check that connection is alive.\n\n*Returns*:\n\n - `true` on success\n - `false` on failure\n\n### `conn:quote()`\n\nQuote a query string.\n\nThrows an error on failure.\n\n*Returns*:\n\n - `quoted_string` on success\n\n### `conn:reset(user, pass, db)`\n\nUpdate the connection authentication settings.\n\n*Options*:\n\n - `user` - username\n - `pass` - password\n - `db` - database name\n\nThrows an error on failure.\n\n### `conn:close()`\n\nClose the individual connection or return it to a pool.\n\nThrows an error on failure.\n\n*Returns*: `true`\n\n### `pool = mysql.pool_create(opts)`\n\nCreate a connection pool with count of size established connections.\n\n*Options*:\n\n - `host` - hostname to connect to\n - `port` - port number to connect to\n - `user` - username\n - `password` - password\n - `db` - database name\n - `size` - count of connections in pool\n - `use_numeric_result` - provide result of the \"conn:execute\" as ordered list\n   (true/false); default value: false\n - `keep_null` - provide printing null fields in the result of the\n   \"conn:execute\" (true/false); default value: false\n\nThrows an error on failure.\n\n*Returns*\n\n - `pool ~= nil` on success\n\n### `conn = pool:get(opts)`\n\nGet a connection from pool. Reset connection before returning it. If connection\nis broken then it will be reestablished.\nIf there is no free connections and timeout is not specified then calling fiber\nwill sleep until another fiber returns some connection to pool.\nIf timeout is specified, and there is no free connections for the duration of the timeout,\nthen the return value is nil.\n\n*Options*:\n\n - `timeout` - maximum number of seconds to wait for a connection\n\n*Returns*:\n\n - `conn ~= nil` on success\n - `conn == nil` on there is no free connections when timeout option is specified\n \n### `pool:put(conn)`\n\nReturn a connection to connection pool.\n\n*Options*\n\n - `conn` - a connection\n\n### `pool:close()`\n\nClose all connections in pool.\n\n*Returns*: `true`\n\n## Comments\n\nAll calls to connections api will be serialized, so it should to be safe to\nuse one connection from some count of fibers. But you should understand,\nthat you can have some unwanted behavior across db calls, for example if\nanother fiber 'injects' some sql between two your calls.\n\n## See Also\n\n * [Tests][]\n * [Tarantool][]\n * [Tarantool Rocks][TarantoolRocks]\n\n[Tarantool]: http://github.com/tarantool/tarantool\n[Tests]: https://github.com/tarantool/mysql/tree/master/test\n[TarantoolRocks]: https://github.com/tarantool/rocks\n\n[testing-actions-badge]: https://github.com/tarantool/mysql/actions/workflows/fast_testing.yml/badge.svg\n[testing-actions-url]: https://github.com/tarantool/mysql/actions/workflows/fast_testing.yml\n[publish-actions-badge]: https://github.com/tarantool/mysql/actions/workflows/publish.yml/badge.svg\n[publish-actions-url]: https://github.com/tarantool/mysql/actions/workflows/publish.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fmysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarantool%2Fmysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fmysql/lists"}