{"id":13513871,"url":"https://github.com/elixir-ecto/db_connection","last_synced_at":"2025-05-14T01:06:06.962Z","repository":{"id":41045235,"uuid":"46829184","full_name":"elixir-ecto/db_connection","owner":"elixir-ecto","description":"Database connection behaviour","archived":false,"fork":false,"pushed_at":"2025-03-17T15:04:54.000Z","size":937,"stargazers_count":324,"open_issues_count":1,"forks_count":115,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-31T16:13:41.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://hexdocs.pm/db_connection/DBConnection.html","language":"Elixir","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/elixir-ecto.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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-11-25T01:17:42.000Z","updated_at":"2025-03-28T16:46:47.000Z","dependencies_parsed_at":"2024-07-17T13:45:06.080Z","dependency_job_id":"b705b302-804a-4972-acb9-fd32051313c4","html_url":"https://github.com/elixir-ecto/db_connection","commit_stats":{"total_commits":441,"total_committers":48,"mean_commits":9.1875,"dds":0.6099773242630385,"last_synced_commit":"93174d09695ef3cf6fecb9e6cf0505a62fc89434"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-ecto%2Fdb_connection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-ecto%2Fdb_connection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-ecto%2Fdb_connection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-ecto%2Fdb_connection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-ecto","download_url":"https://codeload.github.com/elixir-ecto/db_connection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247947818,"owners_count":21023066,"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-01T05:00:39.244Z","updated_at":"2025-04-12T11:45:26.890Z","avatar_url":"https://github.com/elixir-ecto.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# DBConnection\n\nDatabase connection behaviour and database connection pool designed for\nhandling transaction, prepare/execute, cursors and client process\ndescribe/encode/decode.\n\nExamples of using the `DBConnection` behaviour are available in\n`./examples/db_agent/` and `./examples/tcp_connection/`.\n\nThere is also [a series of articles on building database adapters](http://blog.plataformatec.com.br/2018/11/building-a-new-mysql-adapter-for-ecto-part-i-hello-world/). It includes articles covering both DBConnection and Ecto integrations.\n\n## Contributing\n\nRun unit tests with:\n\n    $ mix test\n\nTo run the integration tests (for each available pool):\n\n    $ mix test.pools\n\nTo run all tests:\n\n    $ mix test.all\n\n## Design\n\nThis library is made of four main modules:\n\n  * `DBConnection` - this is the code running on the client\n    and the specification of the DBConnection API\n\n  * `DBConnection.Connection` - this is the process that\n    establishes the database connection\n\n  * `DBConnection.ConnectionPool` - this is the connection\n    pool. A client asks the connection pool for a connection.\n    There is also an ownership pool, used mostly during tests,\n    which we won't discuss here.\n\n  * `DBConnection.Holder` - the holder is responsible for\n    keeping the connection and checkout state. It is modelled\n    by using an ETS table.\n\nOnce a connection is created, it creates a holder and\nassigns the connection pool as the heir. Then the holder\nis promptly given away to the pool. The connection itself\nis mostly a dummy. It is there to handle connections and pings.\nThe state itself (such as the socket) is all in the holder.\n\nOnce there is a checkout, the pool gives the holder to the\nclient process and stores all relevant information in the\nholder table itself. If the client terminates without\nchecking in, then the holder is given back to the pool via\nthe heir mechanism. The pool will then discard the connection.\n\nOne important design detail in DBConnection is that it avoids\ncopying data. Other database libraries would send a request\nto the connection process, perform the query in the connection\nprocess, and then send it back to the client. This means a lot of\ndata copying in Elixir. DBConnection keeps the socket in the\nholder and works on it directly.\n\nDBConnection also takes all of the care necessary to handle\nfailures, and it shuts down the connection and the socket\nwhenever the client does not check in the connection to avoid\nrecycling sockets/connections in a corrupted state (such as a socket\nthat is stuck inside a transaction).\n\n### Deadlines\n\nWhen a checkout happens, a deadline is started by the client\nto send a message to the pool after a time interval. If the\ndeadline is reached and the connection is still checked out,\nthe holder is deleted and the connection is terminated. If the\nclient tries to use a terminated connection, an error will\nbe raised (see `Holder.handle/4`).\n\n### Pool\n\nThe queuing algorithm used by the pool is [CoDel](https://queue.acm.org/appendices/codel.html)\nwhich allows us to plan for overloads and reject requests\nwithout clogging the pool once checkouts do not read a certain\ntarget.\n\n## License\n\nCopyright 2015 James Fish\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-ecto%2Fdb_connection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-ecto%2Fdb_connection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-ecto%2Fdb_connection/lists"}