Module: DataMapper::Adapters::Sqlite3Adapter::Migration::SQL
- Included in:
- DataMapper::Adapters::Sqlite3Adapter::Migration
- Defined in:
- lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb
Instance Method Summary collapse
-
#create_table_statement(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations.
-
#property_schema_statement(schema) ⇒ Object
TODO: move to dm-more/dm-migrations.
-
#sqlite_version ⇒ Object
TODO: move to dm-more/dm-migrations.
-
#supports_serial? ⇒ Boolean
TODO: move to dm-more/dm-migrations.
Instance Method Details
#create_table_statement(repository, model) ⇒ Object
TODO: move to dm-more/dm-migrations
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb', line 52 def create_table_statement(repository, model) statement = <<-EOS.compress_lines CREATE TABLE #{quote_table_name(model.storage_name(repository.name))} (#{model.properties_with_subclasses(repository.name).map { |p| property_schema_statement(property_schema_hash(repository, p)) } * ', '} EOS # skip adding the primary key if one of the columns is serial. In # SQLite the serial column must be the primary key, so it has already # been defined unless model.properties(repository.name).any? { |p| p.serial? } if (key = model.properties(repository.name).key).any? statement << ", PRIMARY KEY(#{key.map { |p| quote_column_name(p.field(repository.name)) } * ', '})" end end statement << ')' statement end |
#property_schema_statement(schema) ⇒ Object
TODO: move to dm-more/dm-migrations
72 73 74 75 76 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb', line 72 def property_schema_statement(schema) statement = super statement << ' PRIMARY KEY AUTOINCREMENT' if supports_serial? && schema[:serial?] statement end |
#sqlite_version ⇒ Object
TODO: move to dm-more/dm-migrations
79 80 81 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb', line 79 def sqlite_version @sqlite_version ||= query('SELECT sqlite_version(*)').first end |
#supports_serial? ⇒ Boolean
TODO: move to dm-more/dm-migrations
47 48 49 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb', line 47 def supports_serial? sqlite_version >= '3.1.0' end |