
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
A Bridgetown plugin to make it easy to integrate and use Sequel, a popular database toolkit for Ruby.
It's been tested only with PostgreSQL, but it should support any of the databases supported by Sequel.
Run these commands to add this plugin along with the database adapter of your choice to your site's Gemfile:
bundle add pg # or sqlite3, etc.
bundle add bridgetown_sequel
Then 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):
database_uri ENV.fetch("DATABASE_URL", "postgres://localhost/your_database_name_here_#{Bridgetown.env}")
except :sequel_tasks do
init :bridgetown_sequel
end
You'll also want to add this plugin's Rake tasks to your Rakefile:
# This is at the top of your Rakefile already:
Bridgetown.load_tasks
# Now add this:
require "bridgetown_sequel"
BridgetownSequel.load_tasks
Finally, you'll want to create a models folder at the top-level of your site repo, as well as a migrations folder.
To add your first database table & model, first you'll want to add a model file to your new models folder. It can look as simple as this:
# models/project.rb
class Project < Sequel::Model
# you can add optional model configuration along with your own Ruby code here later...
end
Next, you'll want to create a migration. Run the following command:
bin/bridgetown db::migrations:new filename=create_projects
And modify the new migrations/001_create_projects.rb file to look something like this:
Sequel.migration do
change do
create_table(:projects) do
primary_key :id
String :name, null: false
String :category
Integer :order, default: 0
DateTime :created_at
DateTime :updated_at
end
end
end
Now let's set up the database and run migrations. First, run this command (you only need to do this once for your repo):
bin/bridgetown db:setup
Then run migrations:
bin/bridgetown db:migrate
This will create the projects table and annotate your models/project.rb file with comments showing the table schema.
Now let's test your model. Run bin/bridgetown console (or bin/bt c for short):
> Project.create(name: "My new project")
> project = Project[1]
You should now see that you can save and load project records in your database.
If you ever need to drop your database and start over, run bin/bridgetown db:drop.
You can pass various options to the bridgetown_sequel initializer to customize the behavior of Sequel:
init :bridgetown_sequel do
connection_options do # pass options to Sequel's `connect` method
# This adds a nice console debugging feature, aka `Project.dataset.print`
extensions [:pretty_table]
end
skip_autoload true # only set to `true` if you're manually configuring your autoload settings
models_dir "another_folder" # change the default `models` to something else
model_setup ->(model) do # here you can add `Sequel::Model` plugins to apply to all your models
model.plugin :update_or_create
end
end
At 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:
> db = Bridgetown.db
> db.fetch("SELECT * FROM projects ORDER BY name desc LIMIT 1").first
> db["SELECT COUNT(*) FROM projects"].first[:count]
Raw 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:
Bridgetown.db.loggers << Bridgetown.logger
For a quick reference on what you can do with the Sequel DSL, check out this handy cheat sheet.
git clone to your local development machine.git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)bundle exec rake test to run the test suitescript/cibuild to validate with Rubocop and Minitest together.FAQs
Unknown package
We found that bridgetown_sequel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.