Created
October 17, 2013 13:41
-
-
Save samueldowens/7025116 to your computer and use it in GitHub Desktop.
database outline for putting data into a DB from an array
This file contains hidden or 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
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