{"id":13877977,"url":"https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter","last_synced_at":"2025-04-05T18:10:58.917Z","repository":{"id":199238730,"uuid":"697664434","full_name":"fractaledmind/activerecord-enhancedsqlite3-adapter","owner":"fractaledmind","description":"ActiveRecord adapter for SQLite that enhances the default. Back-ports generated column support, deferred foreign key support, custom foreign key support, improved default configuration, and adds support for pragma tuning and extension loading","archived":false,"fork":false,"pushed_at":"2024-05-05T19:44:38.000Z","size":67,"stargazers_count":151,"open_issues_count":6,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T17:12:49.689Z","etag":null,"topics":[],"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/fractaledmind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2023-09-28T08:14:29.000Z","updated_at":"2025-03-25T13:05:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"cefcc642-0db1-4329-9cb5-2e97610cbcff","html_url":"https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter","commit_stats":null,"previous_names":["fractaledmind/activerecord-enhancedsqlite3-adapter"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Factiverecord-enhancedsqlite3-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Factiverecord-enhancedsqlite3-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Factiverecord-enhancedsqlite3-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Factiverecord-enhancedsqlite3-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fractaledmind","download_url":"https://codeload.github.com/fractaledmind/activerecord-enhancedsqlite3-adapter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378149,"owners_count":20929297,"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-06T08:01:36.539Z","updated_at":"2025-04-05T18:10:58.877Z","avatar_url":"https://github.com/fractaledmind.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# ActiveRecord Enhanced SQLite3 Adapter\n\nEnhance ActiveRecord's 7.1 SQLite3 adapter. Adds support for:\n\n* generated columns,\n* deferred foreign keys,\n* `PRAGMA` tuning,\n* and extension loading\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n```shell\n$ bundle add activerecord-enhancedsqlite3-adapter\n```\n\n## Usage\n\nThis gem hooks into your Rails application to enhance the `SQLite3Adapter` automatically. No setup required!\n\nOnce installed, you can take advantage of the added features.\n\n### Configuration\n\nOne optional advanced feature is to have this gem isolate reading and writing connection pools. This is useful if you have a large amount of write operations and want to avoid blocking reads.\n\nYou can configure this gem via the Rails configuration object, under the `enhanced_sqlite3` key. Currently, only 1 configuration option is available:\n\n* `isolate_connection_pools` - Whether or not to isolate reading from writing connection pools. See [below](#isolated-connection-pools) for more information.\n\n### Generated columns\n\nYou can now create `virtual` columns, both stored and dynamic. The [SQLite docs](https://www.sqlite.org/gencol.html) explain the difference:\n\n\u003e Generated columns can be either VIRTUAL or STORED. The value of a VIRTUAL column is computed when read, whereas the value of a STORED column is computed when the row is written. STORED columns take up space in the database file, whereas VIRTUAL columns use more CPU cycles when being read.\n\nThe default is to create dynamic/virtual columns.\n\n```ruby\ncreate_table :virtual_columns, force: true do |t|\n  t.string :name\n  t.virtual :upper_name, type: :string, as: \"UPPER(name)\", stored: true\n  t.virtual :lower_name, type: :string, as: \"LOWER(name)\", stored: false\n  t.virtual :octet_name, type: :integer, as: \"LENGTH(name)\"\nend\n```\n\n### Deferred foreign keys\n\nYou can now specify whether or not a foreign key should be deferrable, whether `:deferred` or `:immediate`.\n\n`:deferred` foreign keys mean that the constraint check will be done once the transaction is committed and allows the constraint behavior to change within transaction. `:immediate` means that constraint check is immediate and allows the constraint behavior to change within transaction. The default is `:immediate`.\n\n```ruby\nadd_reference :person, :alias, foreign_key: { deferrable: :deferred }\nadd_reference :alias, :person, foreign_key: { deferrable: :deferred }\n```\n\n### `PRAGMA` tuning\n\nPass any [`PRAGMA` key-value pair](https://www.sqlite.org/pragma.html) under a `pragmas` list in your `config/database.yml` file to ensure that these configuration settings are applied to all database connections.\n\n```yaml\ndefault: \u0026default\n  adapter: sqlite3\n  pool: \u003c%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %\u003e\n  pragmas:\n    # level of database durability, 2 = \"FULL\" (sync on every write), other values include 1 = \"NORMAL\" (sync every 1000 written pages) and 0 = \"NONE\"\n    # https://www.sqlite.org/pragma.html#pragma_synchronous\n    synchronous: \"FULL\"\n```\n\n### Extension loading\n\nThere are a number of [SQLite extensions available as Ruby gems](https://github.com/asg017/sqlite-ecosystem). In order to load the extensions, you need to install the gem (`bundle add {extension-name}`) and then load it into the database connections. In order to support the latter, this gem enhances the `config/database.yml` file to support an `extensions` array. For example, to install and load [an extension](https://github.com/asg017/sqlite-ulid) for supporting [\u003cabbr title=\"Universally Unique Lexicographically Sortable Identifiers\"\u003eULIDs\u003c/abbr\u003e](https://github.com/ulid/spec), we would do:\n\n```shell\n$ bundle add sqlite_ulid\n```\n\nthen\n\n```yaml\ndefault: \u0026default\n  adapter: sqlite3\n  pool: \u003c%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %\u003e\n  extensions:\n    - sqlite_ulid\n```\n\n### Isolated connection pools\n\nBy default, Rails uses a single connection pool for both reading and writing. This can lead to contention if you have a large number of write operations. This gem allows you to isolate the connection pools for reading and writing.\n\nTo enable this feature, set the `isolate_connection_pools` configuration option to `true` in your `config/environments/*.rb` file or `config/application.rb` file:\n\n```ruby\nconfig.enhanced_sqlite3.isolate_connection_pools = true\n```\n\nIf enabled, the gem will patch your application in 3 ways:\n\n1. define separate `reader` and `writer` database configurations\n2. activate Rails' automatic role database switching middleware, defaulting all requests to the `reader` connection pool\n3. patch the ActiveRecord `#transaction` method to switch to the `writer` connection pool for write operations\n4. patch the ActiveRecord `#log` method to log the database name for each database operation\n\nThis feature is experimental and may not work with all Rails configurations. Please report any issues you encounter.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/activerecord-enhancedsqlite3-adapter.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractaledmind%2Factiverecord-enhancedsqlite3-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffractaledmind%2Factiverecord-enhancedsqlite3-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractaledmind%2Factiverecord-enhancedsqlite3-adapter/lists"}