Skip to content

Instantly share code, notes, and snippets.

@samueldowens
Created October 17, 2013 13:41
Show Gist options
  • Save samueldowens/7025116 to your computer and use it in GitHub Desktop.
Save samueldowens/7025116 to your computer and use it in GitHub Desktop.
database outline for putting data into a DB from an array
class Database
@@db = SQLite3::Database.new('articles.db')
@@db.execute("CREATE TABLE if NOT EXISTS articles(id INTEGER PRIMARY KEY ASC, title TEXT UNIQUE, url TEXT, parent_url TEXT, points INTEGER);")
def self.insert(array)
array.each do |article|
sql = "REPLACE INTO articles(title, url, parent_url, points) VALUES (?,?,?,?)"
@@db.execute(sql, article.title, article.url, article.parent_url, article.points)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment