Module: DataMapper::Migrations::Sqlite3Adapter::SQL
- Included in:
- DataMapper::Migrations::Sqlite3Adapter
- Defined in:
- lib/dm-core/migrations.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#create_table_statement(connection, model, properties) ⇒ Object
private
TODO: document.
-
#property_schema_statement(connection, schema) ⇒ Object
private
TODO: document.
-
#query_table(table_name) ⇒ Object
private
TODO: document.
-
#sqlite_version ⇒ Object
private
TODO: document.
-
#supports_drop_table_if_exists? ⇒ Boolean
private
TODO: document.
-
#supports_serial? ⇒ Boolean
private
TODO: document.
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.
TODO: document
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
# File 'lib/dm-core/migrations.rb', line 767 def create_table_statement(connection, model, properties) statement = <<-SQL.compress_lines 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 unless properties.any? { |property| property.serial? } statement << ", PRIMARY KEY(#{properties.key.map { |property| quote_name(property.field) }.join(', ')})" end 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.
TODO: document
786 787 788 789 790 791 792 793 794 |
# File 'lib/dm-core/migrations.rb', line 786 def property_schema_statement(connection, schema) statement = super if supports_serial? && schema[:serial] statement << ' PRIMARY KEY AUTOINCREMENT' end statement end |
#query_table(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.
TODO: document
761 762 763 |
# File 'lib/dm-core/migrations.rb', line 761 def query_table(table_name) query("PRAGMA table_info(#{quote_name(table_name)})") 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.
TODO: document
798 799 800 |
# File 'lib/dm-core/migrations.rb', line 798 def sqlite_version @sqlite_version ||= query('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.
TODO: document
755 756 757 |
# File 'lib/dm-core/migrations.rb', line 755 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.
TODO: document
749 750 751 |
# File 'lib/dm-core/migrations.rb', line 749 def supports_serial? @supports_serial ||= sqlite_version >= '3.1.0' end |