Class: ActiveRecord::ConnectionAdapters::DatastoreAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/datastore_adapter.rb

Defined Under Namespace

Classes: DB

Constant Summary collapse

ADAPTER_NAME =
"Datastore"

Instance Method Summary collapse

Instance Method Details

#adapter_nameObject

:nodoc:



30
31
32
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 30

def adapter_name #:nodoc:
  ADAPTER_NAME
end

#add_column(table_name, column_name, type, options = {}) ⇒ Object Also known as: change_column



103
104
105
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 103

def add_column(table_name, column_name, type, options = {})
  @connection.add_column( table_name, column_name, type, options )
end

#add_index(table_name, column_name, options = {}) ⇒ Object



109
110
111
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 109

def add_index(table_name, column_name, options = {})
  @connection.add_index( table_name, column_name, options )
end

#columns(table_name, name = nil) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 121

def columns( table_name, name = nil)
  @connection.columns( table_name, name ).collect{|k,opt|
    is_primary = opt["type"] == "primary_key"
    c = DataStoreColumn.new( k, opt["default"], is_primary ? "integer" : opt["type"].to_s, opt["null"] )
    c.primary = true if is_primary
    c
  } 
end

#create_table(table_name, options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 81

def create_table( table_name, options = {} )
  log( "CREATE TABLE #{table_name}", "Datastore Adapter" ) {
    td = TableDefinition.new(self)
    td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false

    yield td if block_given?

    fields = {}
    td.columns.each{|c| fields[c.name.to_s] = { "default" => c.default, "type" => c.type.to_s, "null" => c.null } }
    @connection.create_table( table_name, fields )
    td
  }
end

#delete(sql, name = nil) ⇒ Object



68
69
70
71
72
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 68

def delete(sql, name = nil)
  log( "Delete: " + sql.inspect, name ) {
    @connection.delete_query( sql.q )
  }
end

#drop_table(tname, options = {}) ⇒ Object



95
96
97
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 95

def drop_table( tname, options = {} )
  @connection.drop_table( tname )
end

#execute(sql, name = nil) ⇒ Object



75
76
77
78
79
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 75

def execute(sql, name = nil)
  log("Not Support: " + sql, name) {
    #@connection.execute( sql )
  } 
end

#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object



56
57
58
59
60
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 56

def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
  log( "Insert: " + sql.inspect, name ){
    @connection.insert_query( sql )
  }
end

#primary_key(table_name) ⇒ Object



130
131
132
133
134
135
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 130

def primary_key( table_name )
  column = @connection.columns( table_name ).find{|k,opt|
    opt["type"] == "primary_key"
  }
  column ? column[0] : nil
end

#remove_index(table_name, column_name) ⇒ Object



113
114
115
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 113

def remove_index(table_name, column_name )
  @connection.remove_index( table_name, column_name )
end

#rename_table(tname, ntname) ⇒ Object



99
100
101
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 99

def rename_table( tname, ntname )
  @connection.drop_table( tname, ntname )
end

#select(sql, name = nil, binds = []) ⇒ Object



46
47
48
49
50
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 46

def select( sql, name = nil, binds = [] )
  log( sql.inspect, name ) {
    @connection.select_query( sql.q, sql.options )
  }
end

#select_rows(sql, name = nil) ⇒ Object



52
53
54
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 52

def select_rows(sql, name = nil)
  select(sql, name).map{|r| r.map{|k,v| v } }
end

#supports_autoincrement?Boolean

:nodoc:

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 42

def supports_autoincrement? #:nodoc:
  true
end

#supports_migrations?Boolean

:nodoc:

Returns:

  • (Boolean)


34
35
36
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 34

def supports_migrations? #:nodoc:
  true
end

#supports_primary_key?Boolean

:nodoc:

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 38

def supports_primary_key? #:nodoc:
  true
end

#tablesObject



117
118
119
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 117

def tables
  @connection.tables.keys
end

#update(sql, name = nil) ⇒ Object



62
63
64
65
66
# File 'lib/active_record/connection_adapters/datastore_adapter.rb', line 62

def update( sql, name = nil)
  log( "Update: VALUES(#{sql.options[:values].collect{|k,v|k.to_s + " = " + v.inspect}.join(", ")}) " + sql.inspect, name ) {
    @connection.update_query( sql.q, sql.options[:values] )
  }
end