{"id":13804770,"url":"https://github.com/buggins/ddbc","last_synced_at":"2025-05-13T18:32:48.925Z","repository":{"id":387650,"uuid":"9391376","full_name":"buggins/ddbc","owner":"buggins","description":"DDBC is DB Connector for D language (similar to JDBC)","archived":false,"fork":false,"pushed_at":"2025-02-16T18:32:23.000Z","size":6348,"stargazers_count":78,"open_issues_count":17,"forks_count":48,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-02-16T19:29:51.792Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buggins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-04-12T09:55:44.000Z","updated_at":"2025-01-10T05:27:44.000Z","dependencies_parsed_at":"2024-03-29T07:37:16.741Z","dependency_job_id":"e91ec12b-d2c5-4197-8194-bddabd0bc5e2","html_url":"https://github.com/buggins/ddbc","commit_stats":null,"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buggins%2Fddbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buggins%2Fddbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buggins%2Fddbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buggins%2Fddbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buggins","download_url":"https://codeload.github.com/buggins/ddbc/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.765Z","updated_at":"2025-05-13T18:32:47.609Z","avatar_url":"https://github.com/buggins.png","language":"D","funding_links":[],"categories":["Database clients"],"sub_categories":["XML"],"readme":"DDBC\n====\n\n[![DUB Package](https://img.shields.io/dub/v/ddbc.svg)](https://code.dlang.org/packages/ddbc) [![CI](https://github.com/buggins/ddbc/actions/workflows/dub.yml/badge.svg)](https://github.com/buggins/ddbc/actions/workflows/dub.yml) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/buggins/ddbc?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nDDBC is DB Connector for D language (similar to JDBC)\n\nCurrently supports MySQL, PostgreSQL, SQLite and SQL Server (via ODBC).\n\nThe project is hosted on [github](https://github.com/buggins/ddbc) with documentation available on the [wiki](https://github.com/buggins/ddbc/wiki).\n\n\nSee also: [hibernated](https://github.com/buggins/hibernated) - ORM for D language which uses DDBC.\n\n\nNOTE: project has been moved from SourceForge to GitHub\n\n\n## Sample code\n\n```d\nimport ddbc;\nimport std.stdio;\nimport std.conv;\n\nint main(string[] args) {\n\n    // provide URL for proper type of DB\n    string url = \"postgresql://localhost:5432/ddbctestdb?user=ddbctest,password=ddbctestpass,ssl=true\";\n    //string url = \"mysql://localhost:3306/ddbctestdb?user=ddbctest,password=ddbctestpass\";\n    //string url = \"sqlite:testdb.sqlite\";\n\n    // creating Connection\n    auto conn = createConnection(url);\n    scope(exit) conn.close();\n\n    // creating Statement\n    auto stmt = conn.createStatement();\n    scope(exit) stmt.close();\n\n    // execute simple queries to create and fill table\n    stmt.executeUpdate(\"DROP TABLE ddbct1\");\n    stmt.executeUpdate(\"CREATE TABLE ddbct1 \n                    (id bigint not null primary key, \n                     name varchar(250),\n                     comment text,\n                     ts datetime)\");\n    stmt.executeUpdate(\"INSERT INTO ddbct1 (id, name, comment, ts) VALUES\n                        (1, 'name1', 'comment for line 1', '2016/09/14 15:24:01')\");\n    stmt.executeUpdate(\"INSERT INTO ddbct1 (id, name, comment) VALUES\n                        (2, 'name2', 'comment for line 2 - can be very long')\");\n    stmt.executeUpdate(\"INSERT INTO ddbct1 (id, name) values(3, 'name3')\"); // comment is null here\n\n    // reading DB\n    auto rs = stmt.executeQuery(\"SELECT id, name name_alias, comment, ts FROM ddbct1 ORDER BY id\");\n    while (rs.next())\n        writeln(to!string(rs.getLong(1)), \"\\t\", rs.getString(2), \"\\t\", rs.getString(3), \"\\t\", rs.getString(4));\n    return 0;\n}\n```\n\nModule ddbc.pods implement SELECT support for POD structs (plain old data).\n\nInstead of manual reading fields one by one, it's possible to put result set value to struct fields, \nand generate select statements automatically.\n\nSample of easy reading from DB using PODs support:\n\n\n```d\nimport ddbc;\nimport std.stdio;\n\n// provide URL for proper type of DB\n//string url = \"postgresql://localhost:5432/ddbctestdb?user=ddbctest,password=ddbctestpass,ssl=true\";\n//string url = \"mysql://localhost:3306/ddbctestdb?user=ddbctest,password=ddbctestpass\";\nstring url = \"sqlite:testdb.sqlite\";\n// creating Connection\nauto conn = createConnection(url);\nscope(exit) conn.close();\nStatement stmt = conn.createStatement();\nscope(exit) stmt.close();\n// fill database with test data\nstmt.executeUpdate(`DROP TABLE IF EXISTS user_data`);\nstmt.executeUpdate(`CREATE TABLE user_data (id INTEGER PRIMARY KEY, name VARCHAR(255) NOT NULL, flags int null)`);\nstmt.executeUpdate(`INSERT INTO user_data (id, name, flags) VALUES (1, 'John', 5), (2, 'Andrei', 2), (3, 'Walter', 2), (4, 'Rikki', 3), (5, 'Iain', 0), (6, 'Robert', 1)`);\n\n// our POD object\nstruct User {\n    long id;\n    string name;\n    int flags;\n}\n\nwriteln(\"reading all user table rows\");\nforeach(ref e; stmt.select!User) {\n    writeln(\"id:\", e.id, \" name:\", e.name, \" flags:\", e.flags);\n}\n\nwriteln(\"reading user table rows with where and order by\");\nforeach(ref e; stmt.select!User.where(\"id \u003c 6\").orderBy(\"name desc\")) {\n    writeln(\"id:\", e.id, \" name:\", e.name, \" flags:\", e.flags);\n}\n\nwriteln(\"reading user table rows with where and order by with limit and offset\");\nforeach(e; stmt.select!User.where(\"id \u003c 6\").orderBy(\"name desc\").limit(3).offset(1)) {\n    writeln(\"id:\", e.id, \" name:\", e.name, \" flags:\", e.flags);\n}\n\nwriteln(\"reading all user table rows, but fetching only id and name (you will see default value 0 in flags field)\");\nforeach(ref e; stmt.select!(User, \"id\", \"name\")) {\n    writeln(\"id:\", e.id, \" name:\", e.name, \" flags:\", e.flags);\n}\n```\n\n## Connections Strings\n\nConnection strings should start with `ddbc:` followed by the driver type, eg: `ddbc:mysql://localhost`. However, the _ddbc_ prefix is optional.\n\nThe overall format is typically `[ddbc:]\u003cDRIVER:\u003e//[ HOSTNAME [ ,PORT ]] [ ? \u003cPARAMS\u003e }]` except for SQLite\n\n### SQLite\n\nSQLite can be configured for file based persistence or in-memory storage.\n\n```\nddbc:sqlite:ddbc-test.sqlite\n```\n\nAn in memory database can be configured by specifying **:memory:** instead of a filename:\n\n```\nddbc:sqlite::memory:\n```\n\n### MySQL\n\n```\nddbc:mysql://127.0.0.1:3306\n```\n\n### PostgreSQL\n\n```\nddbc:postgresql://127.0.0.1:5432\n\nor\n\nddbc:postgresql://hostname:5432/dbname\n```\n\n### Microsoft SQL Server (via ODBC)\n\n```\nddbc:sqlserver://localhost,1433?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS\n\nor\n\nddbc:odbc://localhost,1433?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS\n```\n\n### Oracle (via ODBC) **experimental**\n\n```\nddbc:oracle://localhost:1521?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS\n\nor\n\nddbc:odbc://localhost:1521?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS\n```\n\n### DSN connections for Microsoft SQL Server\nThe correct format to use for a dsn connection string is `odbc://?dsn=\u003cDSN name\u003e`.\nNote that the server portion before the `?` is empty, so the default server for\nthe DSN name will be used.\n\n## Contributing\n\npull requests are welcome. Please ensure your local branch is up to date and all tests are passing locally before making a pull request. A docker-compose file is included to help with local development. Use `docker-compose up -d` then run `dub test --config=MySQL`, `dub test --config=PGSQL` and `dub test --config=ODBC`. See the `.travis.yml` file and individual driver code for details on creating the relevant databases for local testing.\n\nThe examples should also run, make sure to change to the _example_ directory and run `dub build` then make sure that the compiled executable will run with each supported database (you'll need to install relevant libs and create databases and users with relevant permissions):\n\n```\n./ddbctest --connection=sqlite::memory:\n./ddbctest --connection=mysql:127.0.0.1 --database=testdb --user=travis --password=bbk4k77JKH88g54\n./ddbctest --connection=postgresql:127.0.0.1 --database=testdb --user=postgres\n./ddbctest --connection=odbc://localhost --database=ddbctest --user=SA --password=bbk4k77JKH88g54 --driver=\"ODBC Driver 17 for SQL Server\"\n./ddbctest --connection=odbc://localhost --database=ddbctest --user=SA --password=bbk4k77JKH88g54 --driver=FreeTDS\n```\n\nIn the case of the ODBC connection _FreeTDS_ is just an example, if you have _msodbcsql17_ driver installed use that instead.\n\nAlso, you may want to only run a single database image at a time. In that case you can do `docker-compose up \u003cNAME\u003e`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuggins%2Fddbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuggins%2Fddbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuggins%2Fddbc/lists"}