<commit_before># grape-activerecord

A simple way to use ActiveRecord with your Grape apps. The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them.

## How to use

#### 1. Add it to your Gemfile

    gem "grape-activerecord"

#### 2. Configure your database connection

After loading your gems, tell `Grape::ActiveRecord` about your database config using one of the following examples:

    Grape::ActiveRecord.configure_from_file! "config/database.yml"
    Grape::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
    Grape::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "<PASSWORD>", encoding: "utf8", pool: 10, timeout: 5000)

#### 3. Enable ActiveRecord connection management

This ActiveRecord middleware cleans up your database connections after each request. Add it to your `config.ru` file:

    use ActiveRecord::ConnectionAdapters::ConnectionManagement

#### 4. Import ActiveRecord tasks into your Rakefile

This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.

    require "bundler/setup"
    require "grape/activerecord/rake"

    namespace :db do
      # Some db tasks require your app code to be loaded, or at least your gems
      task :environment do
        require_relative "app"
      end
    end
<commit_msg>Add to the docs an ActiveRecord gotcha<commit_after># grape-activerecord

A simple way to use ActiveRecord with your Grape apps. The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them.

## How to use

#### 1. Add it to your Gemfile

    gem "grape-activerecord"

#### 2. Configure your database connection

After loading your gems, tell `Grape::ActiveRecord` about your database config using one of the following examples:

    Grape::ActiveRecord.configure_from_file! "config/database.yml"
    Grape::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
    Grape::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "<PASSWORD>", encoding: "utf8", pool: 10, timeout: 5000)

**Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.

#### 3. Enable ActiveRecord connection management

This ActiveRecord middleware cleans up your database connections after each request. Add it to your `config.ru` file:

    use ActiveRecord::ConnectionAdapters::ConnectionManagement

#### 4. Import ActiveRecord tasks into your Rakefile

This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.

    require "bundler/setup"
    require "grape/activerecord/rake"

    namespace :db do
      # Some db tasks require your app code to be loaded, or at least your gems
      task :environment do
        require_relative "app"
      end
    end

{'fraction_non_alphanumeric': 0.09433374844333749, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 4.355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2905806', 'n_tokens_mistral': 948, 'n_tokens_neox': 875, 'n_words': 368}