Skip to content

Instantly share code, notes, and snippets.

@pgwillia
Last active May 15, 2025 18:22
Show Gist options
  • Save pgwillia/d1ded56f1b1ca4917b5865a10e08916d to your computer and use it in GitHub Desktop.
Save pgwillia/d1ded56f1b1ca4917b5865a10e08916d to your computer and use it in GitHub Desktop.
Use ActiveRecord + SQLite without Rails (originally https://subinsb.com/ruby-activerecord-sqlite/)
source "https://rubygems.org"
gem "activerecord", "~> 8.0"
gem "pry"
gem "sqlite3", "~> 2.4"
require 'active_record'
require 'pry'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'db.sqlite3'
)
class Place < ActiveRecord::Base
end
@first_run = !Place.table_exists?
# Create the table (migration-like setup)
if @first_run
ActiveRecord::Schema.define do
create_table :places do |t|
t.string :name
t.string :lat
t.string :lon
t.timestamps
end
add_index :places, :name, unique: true
end
end
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment