Organized
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
CONFIG = {
|
||||
database_url: 'postgres://pastemaster:pastemaster@localhost:5432/pastemaster'
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
DB = Sequel.connect(CONFIG[:database_url])
|
||||
|
||||
DB.create_table(:pastes) do
|
||||
primary_key :id
|
||||
String :handle
|
||||
String :type
|
||||
Text :contents
|
||||
end unless DB.table_exists?(:pastes)
|
||||
@@ -0,0 +1,20 @@
|
||||
module Paste
|
||||
def get(params)
|
||||
table.where(params).first
|
||||
end
|
||||
|
||||
def add(params)
|
||||
id = table.insert(params)
|
||||
return unless id.is_a?(Integer)
|
||||
|
||||
get(id: id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def table
|
||||
DB[:pastes]
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
||||
Reference in New Issue
Block a user