Module: DataMapper::Migrations::SqliteAdapter::SQL
- Included in:
- DataMapper::Migrations::SqliteAdapter
- Defined in:
- lib/dm-migrations/adapters/dm-sqlite-adapter.rb
Overview
:nodoc:
Instance Method Summary collapse
- #create_table_statement(connection, model, properties) ⇒ Object private
- #property_schema_statement(connection, schema) ⇒ Object private
- #sqlite_version ⇒ Object private
- #supports_drop_table_if_exists? ⇒ Boolean private
- #supports_serial? ⇒ Boolean private
- #table_info(table_name) ⇒ Object private
Instance Method Details
#create_table_statement(connection, model, properties) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 46 def create_table_statement(connection, model, properties) statement = DataMapper::Ext::String.compress_lines(<<-SQL) CREATE TABLE #{quote_name(model.storage_name(name))} (#{properties.map { |property| property_schema_statement(connection, property_schema_hash(property)) }.join(', ')} SQL # 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 statement << ", PRIMARY KEY(#{properties.key.map { |property| quote_name(property.field) }.join(', ')})" unless properties.any?(&:serial?) statement << ')' statement end |
#property_schema_statement(connection, schema) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 68 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 62 def property_schema_statement(connection, schema) statement = super statement << ' PRIMARY KEY AUTOINCREMENT' if supports_serial? && schema[:serial] statement end |
#sqlite_version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 71 def sqlite_version @sqlite_version ||= select('SELECT sqlite_version(*)').first.freeze end |
#supports_drop_table_if_exists? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 36 def supports_drop_table_if_exists? @supports_drop_table_if_exists ||= sqlite_version >= '3.3.0' end |
#supports_serial? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 31 def supports_serial? @supports_serial ||= sqlite_version >= '3.1.0' end |
#table_info(table_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 41 def table_info(table_name) select("PRAGMA table_info(#{quote_name(table_name)})") end |