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

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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 47

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
  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.



65
66
67
68
69
70
71
72
73
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 65

def property_schema_statement(connection, schema)
  statement = super

  if supports_serial? && schema[:serial]
    statement << ' PRIMARY KEY AUTOINCREMENT'
  end

  statement
end

#sqlite_versionObject

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.



76
77
78
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 76

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.

Returns:

  • (Boolean)


37
38
39
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 37

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.

Returns:

  • (Boolean)


32
33
34
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 32

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.



42
43
44
# File 'lib/dm-migrations/adapters/dm-sqlite-adapter.rb', line 42

def table_info(table_name)
  select("PRAGMA table_info(#{quote_name(table_name)})")
end