{"id":13292140,"url":"https://github.com/bridgetownrb/bridgetown_sequel","last_synced_at":"2026-01-01T19:30:16.748Z","repository":{"id":231375358,"uuid":"781630310","full_name":"bridgetownrb/bridgetown_sequel","owner":"bridgetownrb","description":"Bridgetown plugin for integrating the Sequel database gem","archived":false,"fork":false,"pushed_at":"2024-04-17T04:07:52.000Z","size":36,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T18:15:15.586Z","etag":null,"topics":["bridgetown","bridgetown-plugin","orm","sequel"],"latest_commit_sha":null,"homepage":"","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/bridgetownrb.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":"2024-04-03T18:41:06.000Z","updated_at":"2024-12-08T06:12:45.000Z","dependencies_parsed_at":"2024-10-23T09:31:07.722Z","dependency_job_id":null,"html_url":"https://github.com/bridgetownrb/bridgetown_sequel","commit_stats":null,"previous_names":["bridgetownrb/bridgetown_sequel"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridgetownrb%2Fbridgetown_sequel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridgetownrb%2Fbridgetown_sequel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridgetownrb%2Fbridgetown_sequel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridgetownrb%2Fbridgetown_sequel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bridgetownrb","download_url":"https://codeload.github.com/bridgetownrb/bridgetown_sequel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727047,"owners_count":19687098,"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":["bridgetown","bridgetown-plugin","orm","sequel"],"created_at":"2024-07-29T17:07:22.009Z","updated_at":"2026-01-01T19:30:16.663Z","avatar_url":"https://github.com/bridgetownrb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bridgetown Sequel\n\nA Bridgetown plugin to make it easy to integrate and use [Sequel](https://sequel.jeremyevans.net), a popular database toolkit for Ruby.\n\nIt's been tested only with PostgreSQL, but it should support any of the databases supported by Sequel.\n\n\u003e [!TIP]\n\u003e If you're like me and you greatly prefer YARD's UI to RDoc, check out [Sequel on Gemdocs](https://gemdocs.org/gems/sequel/latest).\n\n## Installation\n\nRun these commands to add this plugin along with the database adapter of your choice to your site's Gemfile:\n\n```shell\nbundle add pg # or sqlite3, etc.\nbundle add bridgetown_sequel\n```\n\nThen add the database URI and initializer to your configuration in `config/initializers.rb` (note that the initializer _must_ be excepted from the `sequel_tasks` context):\n\n```ruby\ndatabase_uri ENV.fetch(\"DATABASE_URL\", \"postgres://localhost/your_database_name_here_#{Bridgetown.env}\")\n\nexcept :sequel_tasks do\n  init :bridgetown_sequel\nend\n```\n\nYou'll also want to add this plugin's Rake tasks to your `Rakefile`:\n\n```rb\n# This is at the top of your Rakefile already:\nBridgetown.load_tasks\n\n# Now add this:\nrequire \"bridgetown_sequel\"\nBridgetownSequel.load_tasks\n```\n\nFinally, you'll want to create a `models` folder at the top-level of your site repo, as well as a `migrations` folder.\n\n### Resolving PostgreSQL fork error on macOS\n\nThere's a bug on macOS which will crash Bridgetown \u0026 Sequel unless you disable PostgreSQL's GSSAPI support (not needed for local development). You'll need to update your configuration as follows:\n\n```rb\ninit :bridgetown_sequel do\n  connection_options do\n    if RUBY_PLATFORM.include?(\"darwin\")\n      driver_options { gssencmode \"disable\" }\n    end\n  end\nend\n```\n\n### Ensuring Puma forks successfully in production\n\nIn production, Bridgetown's Puma server configuration is set to \"clustered mode\" which forks the server process several times. This will result in Sequel connection errors if you don't shut down the database connection first. Update your `config/puma.rb` file so the production config looks like this:\n\n```rb\nif ENV[\"BRIDGETOWN_ENV\"] == \"production\"\n  workers ENV.fetch(\"BRIDGETOWN_CONCURRENCY\") { 4 }\n  before_fork do\n    Bridgetown.db.disconnect if defined?(Bridgetown) \u0026\u0026 Bridgetown.respond_to?(:db)\n  end\nend\n```\n\n## Usage\n\nTo add your first database table \u0026 model, first you'll want to add a model file to your new `models` folder. It can look as simple as this:\n\n```rb\n# models/project.rb\n\nclass Project \u003c Sequel::Model\n  # you can add optional model configuration along with your own Ruby code here later...\nend\n```\n\nLet's set up the database now. Run this command (you only need to do this once for your repo):\n\n```shell\nbin/bridgetown db:setup\n```\n\nNext, you'll want to create a migration. Run the following command:\n\n```shell\nbin/bridgetown db::migrations:new filename=create_projects\n```\n\nAnd modify the new `migrations/001_create_projects.rb` file to look something like this:\n\n```rb\nSequel.migration do\n  change do\n    create_table(:projects) do\n      primary_key :id\n      String :name, null: false\n      String :category\n      Integer :order, default: 0\n\n      DateTime :created_at\n      DateTime :updated_at\n    end\n  end\nend\n```\n\nFinally, run migrations:\n\n```shell\nbin/bridgetown db:migrate\n```\n\nThis will create the `projects` table and annotate your `models/project.rb` file with comments showing the table schema.\n\nNow let's test your model. Run `bin/bridgetown console` (or `bin/bt c` for short):\n\n```rb\n\u003e Project.create(name: \"My new project\")\n\n\u003e project = Project[1]\n```\n\nYou should now see that you can save and load project records in your database.\n\n\u003e [!NOTE]\n\u003e If you ever need to drop your database and start over, run `bin/bridgetown db:drop`.\n\n### Optional Configuration\n\nYou can pass various options to the `bridgetown_sequel` initializer to customize the behavior of Sequel:\n\n```rb\ninit :bridgetown_sequel do\n  connection_options do # pass options to Sequel's `connect` method\n    # This adds a nice console debugging feature, aka `Project.dataset.print`\n    extensions [:pretty_table]\n  end\n  skip_autoload true # only set to `true` if you're manually configuring your autoload settings\n  models_dir \"another_folder\" # change the default `models` to something else\n  model_setup -\u003e(model) do # here you can add `Sequel::Model` plugins to apply to all your models\n    model.plugin :update_or_create \n  end\nend\n```\n\nAt any time after the initializer is run, you can access `Bridgetown.database` (aliased `db`) anywhere in your Ruby code to access the Sequel connection object. (This is equivalent to the `DB` constant you see in a lot of Sequel documentation.) For example, in your console:\n\n```rb\n\u003e db = Bridgetown.db\n\u003e db.fetch(\"SELECT * FROM projects ORDER BY name desc LIMIT 1\").first\n\u003e db[\"SELECT COUNT(*) FROM projects\"].first[:count]\n```\n\nRaw SQL statements won't be logged out-of-the-box, but you can attach Bridgetown's logger to Sequel. Just add this statement right after your initializer:\n\n```rb\nBridgetown.db.loggers \u003c\u003c Bridgetown.logger\n```\n\n----\n\n\u003e [!TIP]\n\u003e For a quick reference on what you can do with the Sequel DSL, check out this [handy cheat sheet](https://devhints.io/sequel).\n\u003e \n\u003e Also read [Sequel on Gemdocs](https://gemdocs.org/gems/sequel/latest), and check out all the [plugins \u0026 database extensions](http://sequel.jeremyevans.net/plugins.html#extensions-database-sequel) you can add to Sequel models.\n\n----\n\n## Contributing\n\n1. Fork it (https://github.com/bridgetownrb/bridgetown_sequel/fork)\n2. Clone the fork using `git clone` to your local development machine.\n3. Create your feature branch (`git checkout -b my-new-feature`)\n4. Commit your changes (`git commit -am 'Add some feature'`)\n5. Push to the branch (`git push origin my-new-feature`)\n6. Create a new Pull Request\n\n## Testing\n\n* Run `script/test` to run the test suite.\n* Or run `script/cibuild` to validate with Rubocop and Minitest together.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridgetownrb%2Fbridgetown_sequel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbridgetownrb%2Fbridgetown_sequel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridgetownrb%2Fbridgetown_sequel/lists"}