{"id":13508911,"url":"https://github.com/elixir-sqlite/sqlitex","last_synced_at":"2025-03-30T11:32:56.857Z","repository":{"id":26386496,"uuid":"29835967","full_name":"elixir-sqlite/sqlitex","owner":"elixir-sqlite","description":"An Elixir wrapper around esqlite. Allows access to sqlite3 databases.","archived":true,"fork":false,"pushed_at":"2021-03-18T20:51:46.000Z","size":259,"stargazers_count":120,"open_issues_count":5,"forks_count":34,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-25T02:40:53.585Z","etag":null,"topics":["database","elixir","elixir-wrapper","esqlite","hex","sqlite3"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/sqlitex","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-sqlite.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-25T23:19:33.000Z","updated_at":"2024-06-18T11:23:48.000Z","dependencies_parsed_at":"2022-08-28T23:20:40.144Z","dependency_job_id":null,"html_url":"https://github.com/elixir-sqlite/sqlitex","commit_stats":null,"previous_names":["mmmries/sqlitex"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-sqlite%2Fsqlitex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-sqlite%2Fsqlitex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-sqlite%2Fsqlitex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-sqlite%2Fsqlitex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-sqlite","download_url":"https://codeload.github.com/elixir-sqlite/sqlitex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314042,"owners_count":20757455,"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","elixir","elixir-wrapper","esqlite","hex","sqlite3"],"created_at":"2024-08-01T02:01:00.355Z","updated_at":"2025-03-30T11:32:56.436Z","avatar_url":"https://github.com/elixir-sqlite.png","language":"Elixir","funding_links":[],"categories":["ORM and Datamapping"],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/Sqlite-Ecto/sqlitex.svg?style=svg)](https://circleci.com/gh/Sqlite-Ecto/sqlitex)\n[![Coverage Status](https://coveralls.io/repos/github/Sqlite-Ecto/sqlitex/badge.svg?branch=master)](https://coveralls.io/github/Sqlite-Ecto/sqlitex?branch=master)\n[![Hex.pm](https://img.shields.io/hexpm/v/sqlitex.svg)](https://hex.pm/packages/sqlitex)\n[![Hex.pm](https://img.shields.io/hexpm/dt/sqlitex.svg)](https://hex.pm/packages/sqlitex)\n\n# Notice\n\nThis library is sparsely maintined. If you are starting a new project, you will probably want to look into using\n[exqlite](https://github.com/elixir-sqlite/exqlite) or it's matching Ecto Adatper [ecto_sqlite3](https://github.com/elixir-sqlite/ecto_sqlite3)\n\n# Sqlitex\n\nAn Elixir wrapper around [esqlite](https://github.com/mmzeeman/esqlite). The main aim here is to provide convenient usage of SQLite databases.\n\n# Updated to 1.0\n\nWith the 1.0 release, we made just a single breaking change. `Sqlitex.Query.query` previously returned just the raw query results on success and `{:error, reason}` on failure.\nThis has been bothering us for a while, so we changed it in 1.0 to return `{:ok, results}` on success and `{:error, reason}` on failure.\nThis should make it easier to pattern match on. The `Sqlitex.Query.query!` function has kept its same functionality of returning bare results on success and raising an error on failure.\n\n# Usage\n\nThe simple way to use `sqlitex` is just to open a database and run a query:\n\n```elixir\nSqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) -\u003e\n  Sqlitex.query(db, \"SELECT * FROM players ORDER BY id LIMIT 1\")\nend)\n# =\u003e [[id: 1, name: \"Mikey\", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil]]\n\nSqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) -\u003e\n  Sqlitex.query(db, \"SELECT * FROM players ORDER BY id LIMIT 1\", into: %{})\nend)\n# =\u003e [%{id: 1, name: \"Mikey\", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil}]\n```\n\nPass the `bind` option to bind parameterized queries.\n\n```elixir\nSqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) -\u003e\n  Sqlitex.query(\n    db,\n    \"INSERT INTO players (name, created_at, updated_at) VALUES (?1, ?2, ?3, ?4)\",\n    bind: ['Mikey', '2012-10-14 05:46:28.318107', '2013-09-06 22:29:36.610911']\n  )\nend)\n# =\u003e [[id: 1, name: \"Mikey\", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil]]\n```\n\nIf you want to keep the database open during the lifetime of your project, you can use the `Sqlitex.Server` GenServer module.\nHere's a sample from a phoenix projects main supervisor definition.\n\n```elixir\nchildren = [\n  # Start the endpoint when the application starts\n  worker(Golf.Endpoint, []),\n  worker(Sqlitex.Server, ['golf.sqlite3', [name: Golf.DB]])\n]\n```\n\nNow that the GenServer is running you can make queries via\n```elixir\nSqlitex.Server.query(Golf.DB,\n                     \"SELECT g.id, g.course_id, g.played_at, c.name AS course\n                      FROM games AS g\n                      INNER JOIN courses AS c ON g.course_id = c.id\n                      ORDER BY g.played_at DESC LIMIT 10\")\n```\n\n# Configuration\n\nSqlitex uses the Erlang library [esqlite](https://github.com/mmzeeman/esqlite)\nwhich accepts a timeout parameter for almost all interactions with the database.\nThe default value for this timeout is 5000 ms. Many functions in Sqlitex accept\na `:db_timeout` option that is passed on to the esqlite calls and also defaults\nto 5000 ms. If required, this default value can be overridden globally with the\nfollowing in your `config.exs`:\n\n```elixir\nconfig :sqlitex, db_timeout: 10_000 # or other positive integer number of ms\n```\n\nAnother esqlite parameter is :db_chunk_size.\nThis is a count of rows to read from native sqlite and send to erlang process in one bulk.\nFor example, the table `mytable` has 1000 rows. We make the query to get all rows with `db_chunk_size: 500` parameter:\n```elixir\nSqlitex.query(db, \"select * from mytable\", db_chunk_size: 500)\n```\nin this case all rows will be passed from native sqlite OS thread to the erlang process in two passes.\nEach pass will contain 500 rows.  \nThis parameter decrease overhead of transmitting rows from native OS sqlite thread to the erlang process by\nchunking list of result rows.  \nPlease, decrease this value if rows are heavy. Default value is 5000.  \nIf you in doubt what to do with this parameter, please, do nothing. Default value is ok.\n```elixir\nconfig :sqlitex, db_chunk_size: 500 # if most of the database rows are heavy\n```\n\n\n# Looking for Ecto?\nCheck out the [SQLite Ecto2 adapter](https://github.com/Sqlite-Ecto/sqlite_ecto2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-sqlite%2Fsqlitex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-sqlite%2Fsqlitex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-sqlite%2Fsqlitex/lists"}