https://github.com/databasecleaner/database_cleaner-sequel
https://github.com/databasecleaner/database_cleaner-sequel
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/databasecleaner/database_cleaner-sequel
- Owner: DatabaseCleaner
- License: mit
- Created: 2016-05-16T01:51:23.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2022-03-08T19:54:29.000Z (over 3 years ago)
- Last Synced: 2025-04-16T00:13:45.154Z (2 months ago)
- Language: Ruby
- Size: 1.07 MB
- Stars: 17
- Watchers: 5
- Forks: 11
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Database Cleaner Adapter for Sequel
[](https://travis-ci.org/DatabaseCleaner/database_cleaner-sequel)
[](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-sequel)
[](https://codecov.io/gh/DatabaseCleaner/database_cleaner-sequel)Clean your Sequel databases with Database Cleaner.
See https://github.com/DatabaseCleaner/database_cleaner for more information.
## Installation
```ruby
# Gemfile
group :test do
gem 'database_cleaner-sequel'
end
``````ruby
# test_helper.rb
DatabaseCleaner[:sequel].strategy = :transactionclass Minitest::Spec
before :each do
DatabaseCleaner[:sequel].start
endafter :each do
DatabaseCleaner[:sequel].clean
end
end
```## Supported Strategies
Three strategies are supported:
* Transaction (default)
* Truncation
* Deletion## Strategy configuration options
The transaction strategy accepts no options.
The truncation and deletion strategies may accept the following options:
* `:only` and `:except` may take a list of table names:
```ruby
# Only truncate the "users" table.
DatabaseCleaner[:sequel].strategy = :truncation, only: ["users"]# Delete all tables except the "users" table.
DatabaseCleaner[:sequel].strategy = :deletion, except: ["users"]
```* `:pre_count` - When set to `true`, this will check each table for existing rows before truncating or deleting it. This can speed up test suites when many of the tables are never populated. Defaults to `false`.
## Adapter configuration options
`#db` defaults to the default Sequel database, but can be specified manually in a few ways:
```ruby
# Sequel connection object
DatabaseCleaner[:sequel].db = Sequel.connect(uri)# Back to default:
DatabaseCleaner[:sequel].db = :default# Multiple Sequel databases can be specified:
DatabaseCleaner[:sequel, db: :default]
DatabaseCleaner[:sequel, db: Sequel.connect(uri)]
```
## COPYRIGHTSee [LICENSE](LICENSE) for details.