{"id":16936458,"url":"https://github.com/jonhoo/msql-srv","last_synced_at":"2025-05-15T10:01:38.489Z","repository":{"id":44454030,"uuid":"114068218","full_name":"jonhoo/msql-srv","owner":"jonhoo","description":"Bindings for writing a server that can act as MySQL/MariaDB","archived":false,"fork":false,"pushed_at":"2025-04-10T14:35:49.000Z","size":694,"stargazers_count":169,"open_issues_count":15,"forks_count":39,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-15T01:49:08.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonhoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"zenodo":null}},"created_at":"2017-12-13T03:18:04.000Z","updated_at":"2025-04-23T10:51:15.000Z","dependencies_parsed_at":"2023-12-17T09:31:41.577Z","dependency_job_id":"e71687f1-c2f9-4484-8307-a8e526de1ec9","html_url":"https://github.com/jonhoo/msql-srv","commit_stats":{"total_commits":280,"total_committers":21,"mean_commits":"13.333333333333334","dds":0.35,"last_synced_commit":"d11e4c805b5201b845258da85e81260413ed17f6"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fmsql-srv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fmsql-srv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fmsql-srv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Fmsql-srv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonhoo","download_url":"https://codeload.github.com/jonhoo/msql-srv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319715,"owners_count":22051072,"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-10-13T20:57:01.938Z","updated_at":"2025-05-15T10:01:38.215Z","avatar_url":"https://github.com/jonhoo.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# msql-srv-rs\n\n[![Crates.io](https://img.shields.io/crates/v/msql_srv.svg)](https://crates.io/crates/msql_srv)\n[![Documentation](https://docs.rs/msql-srv/badge.svg)](https://docs.rs/msql-srv/)\n[![codecov](https://codecov.io/gh/jonhoo/msql-srv/graph/badge.svg?token=RJe5uPCdWI)](https://codecov.io/gh/jonhoo/msql-srv)\n[![Dependency status](https://deps.rs/repo/github/jonhoo/msql-srv/status.svg)](https://deps.rs/repo/github/jonhoo/msql-srv)\n![Maintenance](https://img.shields.io/badge/maintenance-experimental-blue.svg)\n\nBindings for emulating a MySQL/MariaDB server.\n\nWhen developing new databases or caching layers, it can be immensely useful to test your system\nusing existing applications. However, this often requires significant work modifying\napplications to use your database over the existing ones. This crate solves that problem by\nacting as a MySQL server, and delegating operations such as querying and query execution to\nuser-defined logic.\n\nTo start, implement `MysqlShim` for your backend, and create a `MysqlIntermediary` over an\ninstance of your backend and a connection stream. The appropriate methods will be called on\nyour backend whenever a client issues a `QUERY`, `PREPARE`, or `EXECUTE` command, and you will\nhave a chance to respond appropriately. For example, to write a shim that always responds to\nall commands with a \"no results\" reply:\n\n```rust\nextern crate mysql;\nuse msql_srv::*;\nuse mysql::prelude::*;\n\nstruct Backend;\nimpl\u003cW: io::Write\u003e MysqlShim\u003cW\u003e for Backend {\n    type Error = io::Error;\n\n    fn on_prepare(\u0026mut self, _: \u0026str, info: StatementMetaWriter\u003cW\u003e) -\u003e io::Result\u003c()\u003e {\n        info.reply(42, \u0026[], \u0026[])\n    }\n    fn on_execute(\n        \u0026mut self,\n        _: u32,\n        _: ParamParser,\n        results: QueryResultWriter\u003cW\u003e,\n    ) -\u003e io::Result\u003c()\u003e {\n        results.completed(0, 0)\n    }\n    fn on_close(\u0026mut self, _: u32) {}\n\n    fn on_init(\u0026mut self, _: \u0026str, writer: InitWriter\u003cW\u003e) -\u003e io::Result\u003c()\u003e { Ok(()) }\n\n    fn on_query(\u0026mut self, _: \u0026str, results: QueryResultWriter\u003cW\u003e) -\u003e io::Result\u003c()\u003e {\n        let cols = [\n            Column {\n                table: \"foo\".to_string(),\n                column: \"a\".to_string(),\n                coltype: ColumnType::MYSQL_TYPE_LONGLONG,\n                colflags: ColumnFlags::empty(),\n            },\n            Column {\n                table: \"foo\".to_string(),\n                column: \"b\".to_string(),\n                coltype: ColumnType::MYSQL_TYPE_STRING,\n                colflags: ColumnFlags::empty(),\n            },\n        ];\n\n        let mut rw = results.start(\u0026cols)?;\n        rw.write_col(42)?;\n        rw.write_col(\"b's value\")?;\n        rw.finish()\n    }\n}\n\nfn main() {\n    let listener = net::TcpListener::bind(\"127.0.0.1:0\").unwrap();\n    let port = listener.local_addr().unwrap().port();\n\n    let jh = thread::spawn(move || {\n        if let Ok((s, _)) = listener.accept() {\n            MysqlIntermediary::run_on_tcp(Backend, s).unwrap();\n        }\n    });\n\n    let mut db = mysql::Conn::new(\u0026format!(\"mysql://127.0.0.1:{}\", port)).unwrap();\n    assert_eq!(db.ping(), true);\n    assert_eq!(db.query_iter(\"SELECT a, b FROM foo\").unwrap().count(), 1);\n    drop(db);\n    jh.join().unwrap();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Fmsql-srv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonhoo%2Fmsql-srv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Fmsql-srv/lists"}