lib/og/adapters/psql.rb in nitro-0.10.0 vs lib/og/adapters/psql.rb in nitro-0.11.0
- old
+ new
@@ -1,16 +1,16 @@
# * George Moschovitis <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
-# $Id: psql.rb 259 2005-02-15 08:54:54Z gmosx $
+# $Id: psql.rb 266 2005-02-28 14:50:48Z gmosx $
require 'postgres'
require 'og/adapter'
require 'og/connection'
require 'glue/attribute'
-class Og
+module Og
# The PostgreSQL adapter. This adapter communicates with
# an PostgreSQL rdbms. For extra documentation see
# lib/og/adapter.rb
@@ -28,28 +28,10 @@
def self.date(date)
return nil unless date
return "#{date.year}-#{date.month}-#{date.mday}"
end
-
- def write_prop(p)
- if p.klass.ancestors.include?(Integer)
- return "#\{@#{p.symbol} || 'NULL'\}"
- elsif p.klass.ancestors.include?(Float)
- return "#\{@#{p.symbol} || 'NULL'\}"
- elsif p.klass.ancestors.include?(String)
- return "'#\{#{self.class}.escape(@#{p.symbol})\}'"
- elsif p.klass.ancestors.include?(Time)
- return %|#\{@#{p.symbol} ? "'#\{#{self.class}.timestamp(@#{p.symbol})\}'" : 'NULL'\}|
- elsif p.klass.ancestors.include?(Date)
- return %|#\{@#{p.symbol} ? "'#\{#{self.class}.date(@#{p.symbol})\}'" : 'NULL'\}|
- elsif p.klass.ancestors.include?(TrueClass)
- return "#\{@#{p.symbol} ? \"'t'\" : 'NULL' \}"
- else
- return %|#\{@#{p.symbol} ? "'#\{#{self.class}.escape(@#{p.symbol}.to_yaml)\}'" : "''"\}|
- end
- end
def read_prop(p, idx)
if p.klass.ancestors.include?(Integer)
return "res.getvalue(tuple, #{idx}).to_i()"
elsif p.klass.ancestors.include?(Float)
@@ -92,11 +74,11 @@
#{post_cb}
}
end
def new_connection(db)
- return Og::PsqlConnection.new(db)
+ return PsqlConnection.new(db)
end
def calc_field_index(klass, db)
res = db.query "SELECT * FROM #{klass::DBTABLE} LIMIT 1"
meta = db.managed_classes[klass]
@@ -114,19 +96,19 @@
fields = create_fields(klass)
sql = "CREATE TABLE #{klass::DBTABLE} (#{fields.join(', ')}"
- # Create table constrains
+ # Create table constrains.
if klass.__meta and constrains = klass.__meta[:sql_constrain]
sql << ", #{constrains.join(', ')}"
end
sql << ") WITHOUT OIDS;"
- # Create indices
+ # Create indices.
if klass.__meta and indices = klass.__meta[:sql_index]
for data in indices
idx, options = *data
idx = idx.to_s
@@ -222,9 +204,14 @@
@db.adapter.create_db(config[:database], config[:user])
retry
end
raise
end
+ end
+
+ def close
+ @store.close
+ super
end
def query(sql)
Logger.debug sql if $DBG
begin