feat: ✨ begin work on everything :P
This commit is contained in:
parent
03b77c7395
commit
dca5944549
6 changed files with 445 additions and 6 deletions
42
lib/timeseries/hoarder/Table.rb
Normal file
42
lib/timeseries/hoarder/Table.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
|
||||
|
||||
module Timeseries
|
||||
module Hoarder
|
||||
class Table
|
||||
def initialize(db, table_name, table_schema = "public")
|
||||
@table_name = table_name
|
||||
@table_schema = table_schema
|
||||
|
||||
@db = db
|
||||
@pg = @db.pg
|
||||
|
||||
@created = false
|
||||
|
||||
ensure_table_exists
|
||||
end
|
||||
|
||||
def ensure_table_exists
|
||||
return if @created
|
||||
|
||||
@pg.transaction do
|
||||
@pg.exec("SELECT pg_advisory_lock(0)")
|
||||
|
||||
r = @pg.exec_params("SELECT 1 FROM information_schema.tables WHERE table_name = $1 AND table_schema = $2", [@table_name, @schema_name])
|
||||
|
||||
if r.num_tuples >= 1
|
||||
@created = true
|
||||
return
|
||||
end
|
||||
|
||||
table_creation
|
||||
|
||||
@created = true
|
||||
end
|
||||
end
|
||||
|
||||
def table_creation
|
||||
raise "No table creation string method provided!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue