Last active
August 29, 2015 14:22
-
-
Save kariabancroft/22f546c599115ac473c3 to your computer and use it in GitHub Desktop.
Database Creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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