How to generate SQLite files using data loaders? #1266
-
My SQLite workflow is to execute an external script and copy the However, I'm curious about how I could take advantage of the automation provided by data loaders:
It has worked to use an I/O stream to write the file binary to STDOUT, for example: # docs/data/people.sqlite.rb
# Create or open the database
DB_FILENAME = 'people.sqlite'
db = SQLite3::Database.new(DB_FILENAME)
# Create a table if it doesn't exist
db.execute <<-SQL
CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER
);
SQL
# Insert a few rows of data
db.execute "INSERT INTO people (name, age) VALUES (?, ?)", ["Alice", 30]
db.execute "INSERT INTO people (name, age) VALUES (?, ?)", ["Bob", 45]
db.execute "INSERT INTO people (name, age) VALUES (?, ?)", ["Charlie", 25]
db.close
# Write the database file to STDOUT via an IO stream
IO.copy_stream(open(DB_FILENAME, 'rb'), $stdout) I'm only wondering if the documentation is alluding to a different way of generating SQLite files via data loaders? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That seems like a good way of generating sqlite files! |
Beta Was this translation helpful? Give feedback.
That seems like a good way of generating sqlite files!