{"id":19167539,"url":"https://github.com/tomekw/jdbc","last_synced_at":"2025-06-23T18:07:48.476Z","repository":{"id":56878409,"uuid":"80530208","full_name":"tomekw/jdbc","owner":"tomekw","description":"JDBC meets JRuby","archived":false,"fork":false,"pushed_at":"2017-02-28T18:32:19.000Z","size":41,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-09T03:58:09.854Z","etag":null,"topics":["database-adapter","jdbc","jruby","jruby-wrapper","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/tomekw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-31T14:56:32.000Z","updated_at":"2022-02-01T18:29:00.000Z","dependencies_parsed_at":"2022-08-20T23:10:18.441Z","dependency_job_id":null,"html_url":"https://github.com/tomekw/jdbc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tomekw/jdbc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomekw%2Fjdbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomekw%2Fjdbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomekw%2Fjdbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomekw%2Fjdbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomekw","download_url":"https://codeload.github.com/tomekw/jdbc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomekw%2Fjdbc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259747196,"owners_count":22905308,"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":["database-adapter","jdbc","jruby","jruby-wrapper","ruby","ruby-gem"],"created_at":"2024-11-09T09:38:12.146Z","updated_at":"2025-06-14T02:04:49.942Z","avatar_url":"https://github.com/tomekw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JDBC\n\n[![Code Climate](https://codeclimate.com/github/tomekw/jdbc/badges/gpa.svg)](https://codeclimate.com/github/tomekw/jdbc) [![Gem Version](https://badge.fury.io/rb/jdbc.svg)](https://badge.fury.io/rb/jdbc) [![CircleCI](https://circleci.com/gh/tomekw/jdbc.svg?style=svg)](https://circleci.com/gh/tomekw/jdbc)\n\nJDBC meets JRuby.\n\nPlease note the project supports only JRuby (tested with 9.1.7.0+) on Java 8.\n\nThe public API is subject to change before version `1.0.0`.\n\nThe library is in the alpha state. It has been tested only with the `PostgreSQL` database, only basic queries and commands were tested.\nPlease raise issues if any of your use cases is not working and I will be very happy to help!\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"jdbc\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install jdbc\n\n## Public API\n\n| Method                        | Description                                 | Returned value                                              |\n| ----------------------------- | ------------------------------------------- | ----------------------------------------------------------- |\n| `command(sql, bindings = {})` | `INSERT`s, `UPDATE`s, `DELETE`s, etc. calls | Depending on the driver, either full record or primary keys |\n| `ddl(sql, bindings = {})`     | `CREATE TABLES`s, `ADD INDEX`es, etc. calls | `true` or driver exception                                  |\n| `query(sql, bindings = {})`   | `SELECT`s, etc. calls                       | Ruby `Array` of `Hashes`                                    |\n\n## Usage\n\nInstall the database driver, for PostgreSQL:\n\n```ruby\ngem \"jdbc-postgres\"\n```\n\nLoad the the database driver if needed, for PostgreSQL:\n\n```ruby\nrequire \"jdbc/postgres\"\nJdbc::Postgres.load_driver\n```\n\nConfigure the connection pool:\n\n```ruby\ngem \"hucpa\"\n```\n\n```ruby\nrequire \"hucpa\"\n\n# Using the adapter option\noptions = {\n  adapter: :postgresql,\n  database_name: \"jdbc\",\n  password: \"jdbc\",\n  server_name: \"postgres\",\n  username: \"jdbc\"\n}\n\n# Using the jdbc_url option\noptions = {\n  jdbc_url: \"jdbc:postgresql://postgres/jdbc\",\n  password: \"jdbc\",\n  username: \"jdbc\"\n}\n\nconnection_pool = Hucpa::ConnectionPool.new(options)\n\ngateway = JDBC::Gateway.new(connection_pool: connection_pool)\n```\n\nQuery for records:\n\n```ruby\ngateway.query(\"SELECT * FROM things\")\n=\u003e [\n  {\n    id: 1,\n    name: \"Foo\",\n    created_at: Time.parse(\"2017-02-01 10:20:45\")\n  },\n  {\n    id: 2,\n    name: \"Bar\",\n    created_at: Time.parse(\"2017-02-01 10:21:47\")\n  }\n]\n```\n\nQuery bindings can be provided:\n\n```ruby\ngateway.query(\"SELECT * FROM things WHERE name = :name\", name: \"Foo\")\n=\u003e [\n  {\n    id: 1,\n    name: \"Foo\",\n    created_at: Time.parse(\"2017-02-01 10:20:45\")\n  }\n]\n```\n\nOptionally, bindings can be annotated with a [JDBC type](#jdbc-types).\nIt is in fact required when value can be `nil`:\n\n```ruby\ngateway.query(\"SELECT * FROM things WHERE name = :name:VARCHAR OR (name IS NULL AND :name:VARCHAR IS NULL)\", name: nil)\n=\u003e [\n  {\n    id: 3,\n    name: nil,\n    created_at: Time.parse(\"2017-02-02 10:20:45\")\n  }\n]\n```\n\nPass commands:\n\n```ruby\ngateway.command(\"INSERT INTO things (name, created_at) VALUES (:name, :created_at)\", name: \"Foo\", created_at: Time.parse(\"2017-02-02 10:20:45\"))\n=\u003e [\n  {\n    id: 4,\n    name: \"Foo\",\n    created_at: Time.parse(\"2017-02-02 10:20:45\")\n  }\n]\n```\n\n```ruby\ngateway.command(\"UPDATE things SET name = :name WHERE id \u003c :id\", name: \"Bar\", id: 2)\n=\u003e [\n  {\n    id: 1,\n    name: \"Bar\",\n    created_at: Time.parse(\"2017-02-02 10:20:45\")\n  }\n]\n```\n\n```ruby\ngateway.command(\"DELETE FROM things WHERE id = :id\", id: 1)\n=\u003e [\n  {\n    id: 1,\n    name: \"Bar\",\n    created_at: Time.parse(\"2017-02-02 10:20:45\")\n  }\n]\n```\n\nInvoke DDL calls:\n\n```ruby\ngateway.ddl(\"CREATE INDEX name_idx ON things(name)\")\n=\u003e true\n```\n\nClose the connection pool:\n\n```ruby\nconnection_pool.close\n```\n\n## (Known) things that won't work (yet)\n\n* groupping SQL queries / commands in transactions\n\n## JDBC types\n\n* `ARRAY`\n* `BIGINT`\n* `BINARY`\n* `BIT`\n* `BLOB`\n* `BOOLEAN`\n* `CHAR`\n* `CLOB`\n* `DATALINK`\n* `DATE`\n* `DECIMAL`\n* `DISTINCT`\n* `DOUBLE`\n* `FLOAT`\n* `INTEGER`\n* `JAVA_OBJECT`\n* `LONGNVARCHAR`\n* `LONGVARBINARY`\n* `LONGVARCHAR`\n* `NCHAR`\n* `NCLOB`\n* `NULL`\n* `NUMERIC`\n* `NVARCHAR`\n* `OTHER`\n* `REAL`\n* `REF`\n* `REF_CURSOR`\n* `ROWID`\n* `SMALLINT`\n* `SQLXML`\n* `STRUCT`\n* `TIME`\n* `TIME_WITH_TIMEZONE`\n* `TIMESTAMP`\n* `TIMESTAMP_WITH_TIMEZONE`\n* `TINYINT`\n* `VARBINARY`\n* `VARCHAR`\n\n## Development\n\nBuild the Docker image:\n\n    $ docker-compose build\n\nCreate services:\n\n    $ docker-compose create\n\nRun specs:\n\n    $ docker-compose run --rm app rspec spec\n\nRun console:\n\n    $ docker-compose run --rm app irb\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tomekw/jdbc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomekw%2Fjdbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomekw%2Fjdbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomekw%2Fjdbc/lists"}