Skip to content

Instantly share code, notes, and snippets.

@kariabancroft
Last active August 29, 2015 14:22
Show Gist options
  • Save kariabancroft/22f546c599115ac473c3 to your computer and use it in GitHub Desktop.
Save kariabancroft/22f546c599115ac473c3 to your computer and use it in GitHub Desktop.
Database Creation
require "sqlite3"
db = SQLite3::Database.new "test.db"
db.execute "CREATE TABLE posts
(id INTEGER PRIMARY KEY, title TEXT NOT NULL);"
db.close if db
require "sqlite3"
db = SQLite3::Database.open "test.db"
db.execute "INSERT INTO posts (title) VALUES('unigoats');"
# last_row_id = db.last_insert_row_id
# puts last_row_id
select_statement = db.prepare "SELECT * FROM posts;"
results = select_statement.execute
puts results.class
results.each do |row|
puts row
end
results.close if results
db.close if db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment