skyward-orm 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +182 -75
- data/lib/skyward/orm/adapters/postgresql/connection.rb +52 -0
- data/lib/skyward/orm/adapters/postgresql.rb +283 -0
- data/lib/skyward/orm/adapters/sqlite/constraints.rb +172 -0
- data/lib/skyward/orm/adapters/sqlite.rb +317 -0
- data/lib/skyward/orm/adapters.rb +38 -0
- data/lib/skyward/orm/catalog/column.rb +12 -0
- data/lib/skyward/orm/catalog/constraint.rb +13 -0
- data/lib/skyward/orm/catalog/index.rb +11 -0
- data/lib/skyward/orm/catalog/table.rb +10 -0
- data/lib/skyward/orm/catalog.rb +6 -0
- data/lib/skyward/orm/cli/boot_file.rb +43 -0
- data/lib/skyward/orm/cli/migrate.rb +30 -0
- data/lib/skyward/orm/cli/migration.rb +111 -0
- data/lib/skyward/orm/cli/rollback.rb +18 -0
- data/lib/skyward/orm/cli/status.rb +36 -0
- data/lib/skyward/orm/cli.rb +4 -0
- data/lib/skyward/orm/commands.rb +64 -0
- data/lib/skyward/orm/connection/database/schema_check.rb +67 -0
- data/lib/skyward/orm/connection/database.rb +357 -0
- data/lib/skyward/orm/connection/pool.rb +102 -0
- data/lib/skyward/orm/connection/session.rb +38 -0
- data/lib/skyward/orm/connection.rb +7 -0
- data/lib/skyward/orm/members.rb +16 -0
- data/lib/skyward/orm/migration_error.rb +4 -0
- data/lib/skyward/orm/migrations/add_column.rb +7 -0
- data/lib/skyward/orm/migrations/add_constraint.rb +7 -0
- data/lib/skyward/orm/migrations/add_index.rb +7 -0
- data/lib/skyward/orm/migrations/alter_table.rb +12 -0
- data/lib/skyward/orm/migrations/change_default.rb +9 -0
- data/lib/skyward/orm/migrations/change_nullable.rb +8 -0
- data/lib/skyward/orm/migrations/change_type.rb +9 -0
- data/lib/skyward/orm/migrations/create_table.rb +8 -0
- data/lib/skyward/orm/migrations/definitions.rb +176 -0
- data/lib/skyward/orm/migrations/diff.rb +213 -0
- data/lib/skyward/orm/migrations/directory.rb +48 -0
- data/lib/skyward/orm/migrations/discovery.rb +14 -0
- data/lib/skyward/orm/migrations/drop_column.rb +7 -0
- data/lib/skyward/orm/migrations/drop_constraint.rb +7 -0
- data/lib/skyward/orm/migrations/drop_index.rb +7 -0
- data/lib/skyward/orm/migrations/rename_column.rb +8 -0
- data/lib/skyward/orm/migrations/runner/edited.rb +7 -0
- data/lib/skyward/orm/migrations/runner/failed.rb +8 -0
- data/lib/skyward/orm/migrations/runner/irreversible.rb +7 -0
- data/lib/skyward/orm/migrations/runner/locked.rb +8 -0
- data/lib/skyward/orm/migrations/runner/migration.rb +11 -0
- data/lib/skyward/orm/migrations/runner/missing.rb +7 -0
- data/lib/skyward/orm/migrations/runner/raced.rb +7 -0
- data/lib/skyward/orm/migrations/runner.rb +227 -0
- data/lib/skyward/orm/migrations/script.rb +350 -0
- data/lib/skyward/orm/migrations/status.rb +93 -0
- data/lib/skyward/orm/migrations/summary.rb +110 -0
- data/lib/skyward/orm/migrations/versions.rb +19 -0
- data/lib/skyward/orm/migrations.rb +8 -0
- data/lib/skyward/orm/placeholders.rb +37 -0
- data/lib/skyward/orm/pool_timeout.rb +4 -0
- data/lib/skyward/orm/projection.rb +67 -0
- data/lib/skyward/orm/queries/clauses.rb +588 -0
- data/lib/skyward/orm/queries.rb +4 -0
- data/lib/skyward/orm/query.rb +26 -0
- data/lib/skyward/orm/record.rb +96 -0
- data/lib/skyward/orm/schema_mismatch.rb +4 -0
- data/lib/skyward/orm/statements.rb +97 -0
- data/lib/skyward/orm/tables/check.rb +8 -0
- data/lib/skyward/orm/tables/column.rb +10 -0
- data/lib/skyward/orm/tables/column_types.rb +74 -0
- data/lib/skyward/orm/tables/declarations.rb +172 -0
- data/lib/skyward/orm/tables/length.rb +8 -0
- data/lib/skyward/orm/tables/loaded.rb +21 -0
- data/lib/skyward/orm/tables/reference.rb +9 -0
- data/lib/skyward/orm/tables/rows.rb +52 -0
- data/lib/skyward/orm/tables/schema.rb +14 -0
- data/lib/skyward/orm/tables/sql.rb +7 -0
- data/lib/skyward/orm/tables/validation.rb +29 -0
- data/lib/skyward/orm/tables/values.rb +102 -0
- data/lib/skyward/orm/tables.rb +7 -0
- data/lib/skyward/orm/transactional.rb +18 -0
- data/lib/skyward/orm/version.rb +1 -1
- data/lib/skyward/orm/violation.rb +13 -0
- data/lib/skyward/orm/violation_error.rb +13 -0
- data/lib/skyward/orm.rb +72 -1
- data/sig/generated/skyward/orm/adapters/postgresql/connection.rbs +41 -0
- data/sig/generated/skyward/orm/adapters/postgresql.rbs +138 -0
- data/sig/generated/skyward/orm/adapters/sqlite/constraints.rbs +87 -0
- data/sig/generated/skyward/orm/adapters/sqlite.rbs +166 -0
- data/sig/generated/skyward/orm/adapters.rbs +15 -0
- data/sig/generated/skyward/orm/catalog/column.rbs +20 -0
- data/sig/generated/skyward/orm/catalog/constraint.rbs +22 -0
- data/sig/generated/skyward/orm/catalog/index.rbs +20 -0
- data/sig/generated/skyward/orm/catalog/table.rbs +20 -0
- data/sig/generated/skyward/orm/catalog.rbs +5 -0
- data/sig/generated/skyward/orm/cli/boot_file.rbs +21 -0
- data/sig/generated/skyward/orm/cli/migrate.rbs +15 -0
- data/sig/generated/skyward/orm/cli/migration.rbs +45 -0
- data/sig/generated/skyward/orm/cli/rollback.rbs +7 -0
- data/sig/generated/skyward/orm/cli/status.rbs +17 -0
- data/sig/generated/skyward/orm/cli.rbs +4 -0
- data/sig/generated/skyward/orm/commands.rbs +2 -0
- data/sig/generated/skyward/orm/connection/database/schema_check.rbs +31 -0
- data/sig/generated/skyward/orm/connection/database.rbs +226 -0
- data/sig/generated/skyward/orm/connection/pool.rbs +54 -0
- data/sig/generated/skyward/orm/connection/session.rbs +25 -0
- data/sig/generated/skyward/orm/connection.rbs +7 -0
- data/sig/generated/skyward/orm/members.rbs +9 -0
- data/sig/generated/skyward/orm/migration_error.rbs +4 -0
- data/sig/generated/skyward/orm/migrations/add_column.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/add_constraint.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/add_index.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/alter_table.rbs +22 -0
- data/sig/generated/skyward/orm/migrations/change_default.rbs +18 -0
- data/sig/generated/skyward/orm/migrations/change_nullable.rbs +16 -0
- data/sig/generated/skyward/orm/migrations/change_type.rbs +18 -0
- data/sig/generated/skyward/orm/migrations/create_table.rbs +16 -0
- data/sig/generated/skyward/orm/migrations/definitions.rbs +81 -0
- data/sig/generated/skyward/orm/migrations/diff.rbs +99 -0
- data/sig/generated/skyward/orm/migrations/directory.rbs +37 -0
- data/sig/generated/skyward/orm/migrations/discovery.rbs +9 -0
- data/sig/generated/skyward/orm/migrations/drop_column.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/drop_constraint.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/drop_index.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/rename_column.rbs +16 -0
- data/sig/generated/skyward/orm/migrations/runner/edited.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/runner/failed.rbs +16 -0
- data/sig/generated/skyward/orm/migrations/runner/irreversible.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/runner/locked.rbs +16 -0
- data/sig/generated/skyward/orm/migrations/runner/migration.rbs +22 -0
- data/sig/generated/skyward/orm/migrations/runner/missing.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/runner/raced.rbs +14 -0
- data/sig/generated/skyward/orm/migrations/runner.rbs +73 -0
- data/sig/generated/skyward/orm/migrations/script.rbs +161 -0
- data/sig/generated/skyward/orm/migrations/status.rbs +49 -0
- data/sig/generated/skyward/orm/migrations/summary.rbs +50 -0
- data/sig/generated/skyward/orm/migrations/versions.rbs +11 -0
- data/sig/generated/skyward/orm/migrations.rbs +7 -0
- data/sig/generated/skyward/orm/placeholders.rbs +21 -0
- data/sig/generated/skyward/orm/pool_timeout.rbs +4 -0
- data/sig/generated/skyward/orm/projection.rbs +42 -0
- data/sig/generated/skyward/orm/queries/clauses.rbs +367 -0
- data/sig/generated/skyward/orm/queries.rbs +4 -0
- data/sig/generated/skyward/orm/query.rbs +20 -0
- data/sig/generated/skyward/orm/record.rbs +80 -0
- data/sig/generated/skyward/orm/schema_mismatch.rbs +4 -0
- data/sig/generated/skyward/orm/statements.rbs +53 -0
- data/sig/generated/skyward/orm/tables/check.rbs +16 -0
- data/sig/generated/skyward/orm/tables/column.rbs +20 -0
- data/sig/generated/skyward/orm/tables/column_types.rbs +39 -0
- data/sig/generated/skyward/orm/tables/declarations.rbs +87 -0
- data/sig/generated/skyward/orm/tables/length.rbs +16 -0
- data/sig/generated/skyward/orm/tables/loaded.rbs +14 -0
- data/sig/generated/skyward/orm/tables/reference.rbs +18 -0
- data/sig/generated/skyward/orm/tables/rows.rbs +24 -0
- data/sig/generated/skyward/orm/tables/schema.rbs +28 -0
- data/sig/generated/skyward/orm/tables/sql.rbs +14 -0
- data/sig/generated/skyward/orm/tables/validation.rbs +9 -0
- data/sig/generated/skyward/orm/tables/values.rbs +49 -0
- data/sig/generated/skyward/orm/tables.rbs +7 -0
- data/sig/generated/skyward/orm/transactional.rbs +11 -0
- data/sig/generated/skyward/orm/violation.rbs +22 -0
- data/sig/generated/skyward/orm/violation_error.rbs +10 -0
- data/sig/generated/skyward/orm.rbs +29 -0
- data/sig/manual/pg.rbs +31 -0
- data/sig/manual/skyward/orm/adapters/postgresql.rbs +3 -0
- data/sig/manual/skyward/orm/adapters/sqlite/constraints.rbs +3 -0
- data/sig/manual/skyward/orm/adapters/sqlite.rbs +3 -0
- data/sig/manual/skyward/orm/adapters.rbs +3 -0
- data/sig/manual/skyward/orm/cli/boot_file.rbs +3 -0
- data/sig/manual/skyward/orm/cli/migrate.rbs +3 -0
- data/sig/manual/skyward/orm/cli/migration.rbs +3 -0
- data/sig/manual/skyward/orm/cli/rollback.rbs +3 -0
- data/sig/manual/skyward/orm/cli/status.rbs +3 -0
- data/sig/manual/skyward/orm/connection/database/schema_check.rbs +3 -0
- data/sig/manual/skyward/orm/members.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/definitions.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/diff.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/directory.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/discovery.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/runner.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/script.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/status.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/summary.rbs +3 -0
- data/sig/manual/skyward/orm/migrations/versions.rbs +3 -0
- data/sig/manual/skyward/orm/placeholders.rbs +3 -0
- data/sig/manual/skyward/orm/statements.rbs +3 -0
- data/sig/manual/skyward/orm/tables/loaded.rbs +3 -0
- data/sig/manual/skyward/orm/tables/rows.rbs +3 -0
- data/sig/manual/skyward/orm/tables/validation.rbs +3 -0
- data/sig/manual/skyward/orm/tables/values.rbs +3 -0
- data/sig/manual/skyward/orm.rbs +45 -0
- data/sig/manual/sqlite3.rbs +23 -0
- metadata +188 -3
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::ORM::Tables::Values
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
ACCEPTED = {
|
|
7
|
+
integer: [Integer],
|
|
8
|
+
float: [Float, Integer],
|
|
9
|
+
string: [String],
|
|
10
|
+
bool: [TrueClass, FalseClass],
|
|
11
|
+
date: [Date],
|
|
12
|
+
time: [Time]
|
|
13
|
+
}.freeze #: Hash[Symbol, Array[Module]]
|
|
14
|
+
|
|
15
|
+
WRITTEN = {
|
|
16
|
+
integer: "Integer",
|
|
17
|
+
float: "Float",
|
|
18
|
+
string: "String",
|
|
19
|
+
bool: "bool",
|
|
20
|
+
date: "Date",
|
|
21
|
+
time: "Time"
|
|
22
|
+
}.freeze #: Hash[Symbol, String]
|
|
23
|
+
|
|
24
|
+
UNTYPED = "untyped, which takes any value but a Hash or a nested Array" #: String
|
|
25
|
+
|
|
26
|
+
UNTYPED_WRITE = "untyped, which takes any one value but an Array, a Hash or a Range" #: String
|
|
27
|
+
|
|
28
|
+
# @rbs table: singleton(Skyward::ORM::Record)
|
|
29
|
+
# @rbs column: Skyward::ORM::Tables::Column
|
|
30
|
+
# @rbs value: untyped
|
|
31
|
+
# @rbs return: String?
|
|
32
|
+
def mismatch(table, column, value)
|
|
33
|
+
refused = candidates(value).reject { |candidate| accepts?(column, candidate) }
|
|
34
|
+
return if refused.empty?
|
|
35
|
+
|
|
36
|
+
refusal(table, column, refused.first, UNTYPED)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# A write binds each value to one placeholder, so an Array or a Range, which
|
|
40
|
+
# a where unpacks, is never one value, and the driver can't bind a Range.
|
|
41
|
+
# @rbs table: singleton(Skyward::ORM::Record)
|
|
42
|
+
# @rbs column: Skyward::ORM::Tables::Column
|
|
43
|
+
# @rbs value: untyped
|
|
44
|
+
# @rbs return: String?
|
|
45
|
+
def write_mismatch(table, column, value)
|
|
46
|
+
return if accepts?(column, value) && !value.is_a?(Range)
|
|
47
|
+
|
|
48
|
+
refusal(table, column, value, UNTYPED_WRITE)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# @rbs table: singleton(Skyward::ORM::Record)
|
|
54
|
+
# @rbs column: Skyward::ORM::Tables::Column
|
|
55
|
+
# @rbs value: untyped
|
|
56
|
+
# @rbs untyped: String
|
|
57
|
+
# @rbs return: String
|
|
58
|
+
def refusal(table, column, value, untyped)
|
|
59
|
+
"#{table}.#{column.name} is #{written(column, untyped)}, not #{value.inspect} (#{value.class})"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# A range's nil end leaves it open, so it isn't a NULL to check.
|
|
63
|
+
# @rbs value: untyped
|
|
64
|
+
# @rbs return: Array[untyped]
|
|
65
|
+
def candidates(value)
|
|
66
|
+
case value
|
|
67
|
+
when Array then value
|
|
68
|
+
when Range then [value.begin, value.end].compact
|
|
69
|
+
else [value]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @rbs column: Skyward::ORM::Tables::Column
|
|
74
|
+
# @rbs value: untyped
|
|
75
|
+
# @rbs return: bool
|
|
76
|
+
def accepts?(column, value)
|
|
77
|
+
# The driver spreads an Array or a Hash across several placeholders, so
|
|
78
|
+
# neither can be bound as one value, whatever the column's type.
|
|
79
|
+
if column.type == :untyped then !value.is_a?(Array) && !value.is_a?(Hash)
|
|
80
|
+
elsif value.nil? then column.nullable
|
|
81
|
+
elsif column.type == :enum then column.symbols.include?(value)
|
|
82
|
+
# A DateTime is a Date, but it encodes with its time, so it never equals a
|
|
83
|
+
# stored date.
|
|
84
|
+
elsif value.is_a?(DateTime) then false
|
|
85
|
+
# SQLite stores NaN as NULL.
|
|
86
|
+
else ACCEPTED.fetch(column.type).any? { |klass| value.is_a?(klass) } && !(value.is_a?(Float) && value.nan?)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @rbs column: Skyward::ORM::Tables::Column
|
|
91
|
+
# @rbs untyped: String
|
|
92
|
+
# @rbs return: String
|
|
93
|
+
def written(column, untyped)
|
|
94
|
+
case column.type
|
|
95
|
+
when :untyped then untyped
|
|
96
|
+
when :enum
|
|
97
|
+
symbols = column.symbols.map(&:inspect).join(" | ")
|
|
98
|
+
column.nullable ? "(#{symbols})?" : symbols
|
|
99
|
+
else "#{WRITTEN.fetch(column.type)}#{"?" if column.nullable}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @rbs module-self Minitest::Test::LifecycleHooks
|
|
4
|
+
module Skyward::ORM::Transactional
|
|
5
|
+
# @rbs return: void
|
|
6
|
+
def before_setup
|
|
7
|
+
Skyward::ORM::Connection::SESSION.database.hold
|
|
8
|
+
super
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Minitest calls this even when setup or the test raised.
|
|
12
|
+
# @rbs return: void
|
|
13
|
+
def after_teardown
|
|
14
|
+
super
|
|
15
|
+
ensure
|
|
16
|
+
Skyward::ORM::Connection::SESSION.database.release
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/skyward/orm/version.rb
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::ORM
|
|
4
|
+
# @rbs!
|
|
5
|
+
# type violation_kind = :unique | :foreign_key | :not_null | :check
|
|
6
|
+
|
|
7
|
+
Violation = Data.define(
|
|
8
|
+
:kind, #: violation_kind
|
|
9
|
+
:constraint, #: String?
|
|
10
|
+
:columns, #: Array[Symbol]
|
|
11
|
+
:message #: String
|
|
12
|
+
)
|
|
13
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Skyward::ORM::ViolationError < StandardError
|
|
4
|
+
# @dynamic violation
|
|
5
|
+
attr_reader :violation #: Skyward::ORM::Violation
|
|
6
|
+
|
|
7
|
+
# @rbs violation: Skyward::ORM::Violation
|
|
8
|
+
# @rbs return: void
|
|
9
|
+
def initialize(violation)
|
|
10
|
+
super(violation.message)
|
|
11
|
+
@violation = violation
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/skyward/orm.rb
CHANGED
|
@@ -1,11 +1,82 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "date"
|
|
3
4
|
require "skyward/core"
|
|
4
5
|
require "zeitwerk"
|
|
5
6
|
require_relative "orm/version"
|
|
6
7
|
|
|
7
8
|
loader = Zeitwerk::Loader.for_gem_extension(Skyward)
|
|
8
|
-
loader.inflector.inflect(
|
|
9
|
+
loader.inflector.inflect(
|
|
10
|
+
"orm" => "ORM", "sql" => "SQL", "sqlite" => "SQLite", "postgresql" => "PostgreSQL", "cli" => "CLI"
|
|
11
|
+
)
|
|
9
12
|
# The skyward executable loads it, and it defines no constant.
|
|
10
13
|
loader.ignore("#{__dir__}/orm/commands.rb")
|
|
11
14
|
loader.setup
|
|
15
|
+
|
|
16
|
+
# An app's signatures subclass Skyward::ORM::Record, so RBS needs its declaration.
|
|
17
|
+
dir = __dir__ #: String
|
|
18
|
+
Skyward::Core::Signatures.register(File.expand_path("../../sig", dir))
|
|
19
|
+
|
|
20
|
+
module Skyward
|
|
21
|
+
# @rbs url: String
|
|
22
|
+
# @rbs signatures: String
|
|
23
|
+
# @rbs pool: Integer
|
|
24
|
+
# @rbs check: bool
|
|
25
|
+
# @rbs return: ORM::Connection::Database
|
|
26
|
+
def self.connect(url, signatures: "sig", pool: 5, check: ORM::Connection::SESSION.check?)
|
|
27
|
+
column_types = ORM::Tables::ColumnTypes.new(Core::Types::Reader.new(Core::Signatures.load(signatures)))
|
|
28
|
+
adapter, location = ORM::Adapters.resolve(
|
|
29
|
+
url,
|
|
30
|
+
schemes: ORM::Adapters::SCHEMES,
|
|
31
|
+
requirer: ->(feature) { require(feature) }
|
|
32
|
+
)
|
|
33
|
+
connections = ORM::Connection::Pool.new(adapter.pool_size(location, pool), -> { adapter.connect(location) })
|
|
34
|
+
tables = connections.with { |connection| adapter.tables(connection) }
|
|
35
|
+
database = ORM::Connection::Database.new(adapter, connections, column_types, tables, check:)
|
|
36
|
+
database.check(ORM::Tables::Loaded.table_classes(ORM::Record)) if check
|
|
37
|
+
ORM::Connection::SESSION.connect(database)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @rbs [T] () { () -> T } -> T
|
|
41
|
+
def self.transaction(&) = ORM::Connection::SESSION.database.transaction(&)
|
|
42
|
+
|
|
43
|
+
# @rbs return: bool
|
|
44
|
+
def self.transaction? = ORM::Connection::SESSION.database.transaction?
|
|
45
|
+
|
|
46
|
+
# @rbs [T] (ORM::_Row[T] row, String sql, *untyped values) -> Array[T]
|
|
47
|
+
# | (String sql, *untyped values) -> Array[Hash[Symbol, untyped]]
|
|
48
|
+
# Steep checks the body against both overloads at once, as one whose second
|
|
49
|
+
# parameter is optional, which neither overload's is.
|
|
50
|
+
def self.query(row, *arguments) # steep:ignore DifferentMethodParameterKind
|
|
51
|
+
database = ORM::Connection::SESSION.database
|
|
52
|
+
case row
|
|
53
|
+
when String then database.hashes(row, arguments)
|
|
54
|
+
when Class then database.rows(row, arguments.fetch(0), arguments.drop(1))
|
|
55
|
+
else raise ArgumentError, "Skyward.query takes a row class or the SQL as its first argument"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @rbs directory: String
|
|
60
|
+
# @rbs return: Array[String]
|
|
61
|
+
def self.migrate(directory)
|
|
62
|
+
database = ORM::Connection::SESSION.database
|
|
63
|
+
migrated = database.migrate(ORM::Migrations::Runner.read(directory))
|
|
64
|
+
case migrated
|
|
65
|
+
when Array
|
|
66
|
+
database.check(ORM::Tables::Loaded.table_classes(ORM::Record))
|
|
67
|
+
migrated
|
|
68
|
+
else raise ORM::MigrationError, ORM::Migrations::Runner.message(migrated)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# @rbs expression: String
|
|
73
|
+
# @rbs return: ORM::Tables::SQL
|
|
74
|
+
def self.sql(expression)
|
|
75
|
+
# Steep knows expression is a String, but untyped code can pass anything.
|
|
76
|
+
unless expression.is_a?(String) # steep:ignore UnreachableBranch
|
|
77
|
+
raise ArgumentError, "Skyward.sql takes the SQL as a String, not #{expression.inspect}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
ORM::Tables::SQL.new(expression: expression.dup.freeze)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Generated from lib/skyward/orm/adapters/postgresql/connection.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
# PG::Connection runs SQL with exec_params, which returns a PG::Result, so this
|
|
4
|
+
# gives it the execute every adapter's connection has.
|
|
5
|
+
class Skyward::ORM::Adapters::PostgreSQL::Connection
|
|
6
|
+
@connection: PG::Connection
|
|
7
|
+
|
|
8
|
+
@changes: Integer
|
|
9
|
+
|
|
10
|
+
# @rbs connection: PG::Connection
|
|
11
|
+
# @rbs return: void
|
|
12
|
+
def initialize: (PG::Connection connection) -> void
|
|
13
|
+
|
|
14
|
+
# The block form clears each result as soon as its rows are read, so the
|
|
15
|
+
# rows it changed are kept for changes, as SQLite keeps them for its own.
|
|
16
|
+
# @rbs sql: String
|
|
17
|
+
# @rbs binds: Array[untyped]
|
|
18
|
+
# @rbs return: Array[Array[String?]]
|
|
19
|
+
def execute: (String sql, ?Array[untyped] binds) -> Array[Array[String?]]
|
|
20
|
+
|
|
21
|
+
# @dynamic changes
|
|
22
|
+
attr_reader changes: Integer
|
|
23
|
+
|
|
24
|
+
# @rbs sql: String
|
|
25
|
+
# @rbs *binds: untyped
|
|
26
|
+
# @rbs return: Array[Array[String?]]
|
|
27
|
+
def execute2: (String sql, *untyped binds) -> Array[Array[String?]]
|
|
28
|
+
|
|
29
|
+
# exec, unlike exec_params, runs every statement in the SQL.
|
|
30
|
+
# @rbs sql: String
|
|
31
|
+
# @rbs return: void
|
|
32
|
+
def execute_batch: (String sql) -> void
|
|
33
|
+
|
|
34
|
+
# Anything but idle counts, so a connection left mid-command or broken isn't
|
|
35
|
+
# reused either.
|
|
36
|
+
# @rbs return: bool
|
|
37
|
+
def transaction_active?: () -> bool
|
|
38
|
+
|
|
39
|
+
# @rbs return: void
|
|
40
|
+
def close: () -> void
|
|
41
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Generated from lib/skyward/orm/adapters/postgresql.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::ORM::Adapters::PostgreSQL
|
|
4
|
+
SQL_TYPES: Hash[Skyward::ORM::Tables::column_type, String]
|
|
5
|
+
|
|
6
|
+
# As the catalog spells each type, which compatible? is given.
|
|
7
|
+
COMPATIBLE: Hash[Skyward::ORM::Tables::column_type, Array[String]]
|
|
8
|
+
|
|
9
|
+
# The catalog puts a length or precision in parentheses.
|
|
10
|
+
MODIFIER: Regexp
|
|
11
|
+
|
|
12
|
+
# UTC, so a timestamp column, which has no zone, holds the same instant as a
|
|
13
|
+
# timestamptz, and to the microsecond, as PostgreSQL keeps it. Its trailing
|
|
14
|
+
# zeros go, as PostgreSQL writes a time back, so a default compares as text.
|
|
15
|
+
TIME_FORMAT: String
|
|
16
|
+
|
|
17
|
+
TRAILING_ZEROS: Regexp
|
|
18
|
+
|
|
19
|
+
# PostgreSQL reads a literal default back cast to its type, as 'normal'::text,
|
|
20
|
+
# and quotes a number that isn't a plain integer or decimal, as '-1'::integer.
|
|
21
|
+
CAST: Regexp
|
|
22
|
+
|
|
23
|
+
NUMERIC: Regexp
|
|
24
|
+
|
|
25
|
+
# Float() refuses the special values PostgreSQL writes out.
|
|
26
|
+
SPECIAL_FLOATS: Hash[String, Float]
|
|
27
|
+
|
|
28
|
+
MIGRATION_LOCK: Integer
|
|
29
|
+
|
|
30
|
+
# Each value comes back as text, and a boolean as t or f.
|
|
31
|
+
TRUE_TEXT: String
|
|
32
|
+
|
|
33
|
+
VIOLATIONS: Hash[String, Skyward::ORM::violation_kind]
|
|
34
|
+
|
|
35
|
+
CONSTRAINT_KINDS: Hash[String, Skyward::ORM::Catalog::constraint_kind]
|
|
36
|
+
|
|
37
|
+
# The tables an unqualified name finds, as every query names them.
|
|
38
|
+
TABLES: String
|
|
39
|
+
|
|
40
|
+
COLUMNS: String
|
|
41
|
+
|
|
42
|
+
# Leaves out the indexes primary keys and unique constraints make, as SQLite's does.
|
|
43
|
+
INDEXES: String
|
|
44
|
+
|
|
45
|
+
# A check on no column has no conkey, so the join keeps it with no columns.
|
|
46
|
+
CONSTRAINTS: String
|
|
47
|
+
|
|
48
|
+
# @rbs return: String
|
|
49
|
+
def driver: () -> String
|
|
50
|
+
|
|
51
|
+
# Values are decoded from PostgreSQL's ISO text, whatever the server's
|
|
52
|
+
# defaults, and times read and written in UTC. libpq prints each notice the
|
|
53
|
+
# server sends, so only warnings and worse are sent, or `skyward migrate`
|
|
54
|
+
# would print that schema_migrations already exists.
|
|
55
|
+
# @rbs location: String
|
|
56
|
+
# @rbs return: Skyward::ORM::_Connection
|
|
57
|
+
def connect: (String location) -> Skyward::ORM::_Connection
|
|
58
|
+
|
|
59
|
+
# @rbs (String _location, Integer size) -> Integer
|
|
60
|
+
def pool_size: (String _location, Integer size) -> Integer
|
|
61
|
+
|
|
62
|
+
# @rbs position: Integer
|
|
63
|
+
# @rbs return: String
|
|
64
|
+
def placeholder: (Integer position) -> String
|
|
65
|
+
|
|
66
|
+
# PostgreSQL takes an OFFSET with no LIMIT before it.
|
|
67
|
+
# @rbs return: String?
|
|
68
|
+
def unlimited: () -> String?
|
|
69
|
+
|
|
70
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
71
|
+
# @rbs return: String?
|
|
72
|
+
def sql_type: (Skyward::ORM::Tables::column_type type) -> String?
|
|
73
|
+
|
|
74
|
+
# @rbs return: String?
|
|
75
|
+
def identity: () -> String?
|
|
76
|
+
|
|
77
|
+
# @rbs return: bool
|
|
78
|
+
def alters_in_place?: () -> bool
|
|
79
|
+
|
|
80
|
+
# A second migrator waits at the lock until the first commits, and then sees
|
|
81
|
+
# what it ran. Any fixed key will do: the lock is the database's own.
|
|
82
|
+
# @rbs return: String
|
|
83
|
+
def begin_migration: () -> String
|
|
84
|
+
|
|
85
|
+
# PostgreSQL checks each foreign key as the migration writes.
|
|
86
|
+
# @rbs (Skyward::ORM::_Connection _connection) -> Array[String]
|
|
87
|
+
def foreign_key_violations: (Skyward::ORM::_Connection _connection) -> Array[String]
|
|
88
|
+
|
|
89
|
+
# Ending the transaction released the lock, and nothing else was set.
|
|
90
|
+
# @rbs return: String
|
|
91
|
+
def end_migration: () -> String
|
|
92
|
+
|
|
93
|
+
# @rbs expression: String
|
|
94
|
+
# @rbs return: String
|
|
95
|
+
def default_expression: (String expression) -> String
|
|
96
|
+
|
|
97
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
98
|
+
# @rbs sql_type: String
|
|
99
|
+
# @rbs return: bool
|
|
100
|
+
def compatible?: (Skyward::ORM::Tables::column_type type, String sql_type) -> bool
|
|
101
|
+
|
|
102
|
+
# The driver sends every other value as its to_s, which PostgreSQL reads.
|
|
103
|
+
# @rbs value: untyped
|
|
104
|
+
# @rbs return: untyped
|
|
105
|
+
def encode: (untyped value) -> untyped
|
|
106
|
+
|
|
107
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
108
|
+
# @rbs value: untyped
|
|
109
|
+
# @rbs return: untyped
|
|
110
|
+
def decode: (Skyward::ORM::Tables::column_type type, untyped value) -> untyped
|
|
111
|
+
|
|
112
|
+
# @rbs (Skyward::ORM::_Connection connection) -> Array[Skyward::ORM::Catalog::Table]
|
|
113
|
+
def tables: (Skyward::ORM::_Connection connection) -> Array[Skyward::ORM::Catalog::Table]
|
|
114
|
+
|
|
115
|
+
# @rbs (StandardError error, Array[Skyward::ORM::Catalog::Table] tables, Symbol? _table)
|
|
116
|
+
# -> Skyward::ORM::Violation?
|
|
117
|
+
def violation: (StandardError error, Array[Skyward::ORM::Catalog::Table] tables, Symbol? _table) -> Skyward::ORM::Violation?
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
# @rbs rows: Array[Array[untyped]]
|
|
122
|
+
# @rbs return: Array[Skyward::ORM::Catalog::Index]
|
|
123
|
+
def indexes: (Array[Array[untyped]] rows) -> Array[Skyward::ORM::Catalog::Index]
|
|
124
|
+
|
|
125
|
+
# @rbs rows: Array[Array[untyped]]
|
|
126
|
+
# @rbs return: Array[Skyward::ORM::Catalog::Constraint]
|
|
127
|
+
def constraints: (Array[Array[untyped]] rows) -> Array[Skyward::ORM::Catalog::Constraint]
|
|
128
|
+
|
|
129
|
+
# @rbs expression: String?
|
|
130
|
+
# @rbs return: String?
|
|
131
|
+
def default: (String? expression) -> String?
|
|
132
|
+
|
|
133
|
+
# @rbs tables: Array[Skyward::ORM::Catalog::Table]
|
|
134
|
+
# @rbs table: String?
|
|
135
|
+
# @rbs name: String?
|
|
136
|
+
# @rbs return: Array[Symbol]
|
|
137
|
+
def constrained: (Array[Skyward::ORM::Catalog::Table] tables, String? table, String? name) -> Array[Symbol]
|
|
138
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Generated from lib/skyward/orm/adapters/sqlite/constraints.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
# SQLite keeps no catalog of constraints, only each table's CREATE TABLE
|
|
4
|
+
# statement, so their names, kinds, columns and definitions are read from that.
|
|
5
|
+
module Skyward::ORM::Adapters::SQLite::Constraints
|
|
6
|
+
type token = [ Symbol, String, Integer, Integer ]
|
|
7
|
+
|
|
8
|
+
TOKEN: Regexp
|
|
9
|
+
|
|
10
|
+
DEPTH: Hash[Symbol, Integer]
|
|
11
|
+
|
|
12
|
+
NAMES: Array[Symbol]
|
|
13
|
+
|
|
14
|
+
TABLE_CONSTRAINTS: Array[String]
|
|
15
|
+
|
|
16
|
+
KINDS: Hash[String, Skyward::ORM::Catalog::constraint_kind]
|
|
17
|
+
|
|
18
|
+
# The words that start a column's next constraint, or its default or collation.
|
|
19
|
+
COLUMN_CLAUSES: Array[String]
|
|
20
|
+
|
|
21
|
+
# A reference's ON DELETE SET NULL and SET DEFAULT end in these.
|
|
22
|
+
SET_TO: Array[String]
|
|
23
|
+
|
|
24
|
+
# @rbs sql: String
|
|
25
|
+
# @rbs columns: Array[Symbol]
|
|
26
|
+
# @rbs return: Array[Skyward::ORM::Catalog::Constraint]
|
|
27
|
+
def read: (String sql, Array[Symbol] columns) -> Array[Skyward::ORM::Catalog::Constraint]
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# The scan covers every character, since its last alternative matches any
|
|
32
|
+
# one, so each token starts where the one before it ends.
|
|
33
|
+
# @rbs sql: String
|
|
34
|
+
# @rbs return: Array[Array[[token, Integer]]]
|
|
35
|
+
def definitions: (String sql) -> Array[Array[[ token, Integer ]]]
|
|
36
|
+
|
|
37
|
+
# @rbs text: String
|
|
38
|
+
# @rbs start: Integer
|
|
39
|
+
# @rbs return: token?
|
|
40
|
+
def token: (String text, Integer start) -> token?
|
|
41
|
+
|
|
42
|
+
# A column's own constraints are on that column. A table constraint names
|
|
43
|
+
# its columns in parentheses, and a check is on the columns its expression
|
|
44
|
+
# mentions.
|
|
45
|
+
# @rbs sql: String
|
|
46
|
+
# @rbs definition: Array[[token, Integer]]
|
|
47
|
+
# @rbs columns: Array[Symbol]
|
|
48
|
+
# @rbs return: Array[Skyward::ORM::Catalog::Constraint]
|
|
49
|
+
def constraints: (String sql, Array[[ token, Integer ]] definition, Array[Symbol] columns) -> Array[Skyward::ORM::Catalog::Constraint]
|
|
50
|
+
|
|
51
|
+
# A column's constraint, written as the table constraint it's the same as.
|
|
52
|
+
# @rbs sql: String
|
|
53
|
+
# @rbs kind: Skyward::ORM::Catalog::constraint_kind
|
|
54
|
+
# @rbs column: Symbol
|
|
55
|
+
# @rbs rest: Array[[token, Integer]]
|
|
56
|
+
# @rbs return: String
|
|
57
|
+
def on_column: (String sql, Skyward::ORM::Catalog::constraint_kind kind, Symbol column, Array[[ token, Integer ]] rest) -> String
|
|
58
|
+
|
|
59
|
+
# A column constraint runs until the column's next clause. ON DELETE SET
|
|
60
|
+
# NULL and NOT DEFERRABLE are inside a reference, though, not clauses of
|
|
61
|
+
# their own.
|
|
62
|
+
# @rbs rest: Array[[token, Integer]]
|
|
63
|
+
# @rbs return: Array[token]
|
|
64
|
+
def own: (Array[[ token, Integer ]] rest) -> Array[token]
|
|
65
|
+
|
|
66
|
+
# @rbs sql: String
|
|
67
|
+
# @rbs tokens: Array[token]
|
|
68
|
+
# @rbs return: String
|
|
69
|
+
def text: (String sql, Array[token] tokens) -> String
|
|
70
|
+
|
|
71
|
+
# @rbs token: token
|
|
72
|
+
# @rbs return: String?
|
|
73
|
+
def word: (token token) -> String?
|
|
74
|
+
|
|
75
|
+
# @rbs rest: Array[[token, Integer]]
|
|
76
|
+
# @rbs return: Array[token]
|
|
77
|
+
def first_parenthesized: (Array[[ token, Integer ]] rest) -> Array[token]
|
|
78
|
+
|
|
79
|
+
# @rbs tokens: Array[token]
|
|
80
|
+
# @rbs columns: Array[Symbol]
|
|
81
|
+
# @rbs return: Array[Symbol]
|
|
82
|
+
def mentioned: (Array[token] tokens, Array[Symbol] columns) -> Array[Symbol]
|
|
83
|
+
|
|
84
|
+
# @rbs tokens: Array[token]
|
|
85
|
+
# @rbs return: Symbol
|
|
86
|
+
def referenced: (Array[token] tokens) -> Symbol
|
|
87
|
+
end
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Generated from lib/skyward/orm/adapters/sqlite.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::ORM::Adapters::SQLite
|
|
4
|
+
# The first SQLite with RETURNING, which every write into a row class uses.
|
|
5
|
+
MINIMUM_VERSION: Gem::Version
|
|
6
|
+
|
|
7
|
+
SQL_TYPES: Hash[Skyward::ORM::Tables::column_type, String]
|
|
8
|
+
|
|
9
|
+
# Fixed width and UTC, so text order is time order, and to the microsecond,
|
|
10
|
+
# as PostgreSQL keeps it. It's the format of SQLite's own CURRENT_TIMESTAMP,
|
|
11
|
+
# with the fraction added, so the two compare.
|
|
12
|
+
TIME_FORMAT: String
|
|
13
|
+
|
|
14
|
+
# SQLite's extended result codes: SQLITE_CONSTRAINT_CHECK, _FOREIGNKEY,
|
|
15
|
+
# _NOTNULL, _PRIMARYKEY and _UNIQUE.
|
|
16
|
+
VIOLATIONS: Hash[Integer, Skyward::ORM::violation_kind]
|
|
17
|
+
|
|
18
|
+
# SQLite enforces a RESTRICT foreign key as a trigger would, so it reports
|
|
19
|
+
# SQLITE_CONSTRAINT_TRIGGER, and only the message tells it from a trigger's RAISE.
|
|
20
|
+
TRIGGER: Integer
|
|
21
|
+
|
|
22
|
+
RESTRICTED: String
|
|
23
|
+
|
|
24
|
+
UNIQUE_KINDS: Array[Skyward::ORM::Catalog::constraint_kind]
|
|
25
|
+
|
|
26
|
+
BUSY_TIMEOUT_MS: Integer
|
|
27
|
+
|
|
28
|
+
COLUMNS: String
|
|
29
|
+
|
|
30
|
+
INDEXES: String
|
|
31
|
+
|
|
32
|
+
# What SQLite takes as a default without parentheses: a string, blob or
|
|
33
|
+
# number, NULL, TRUE or FALSE.
|
|
34
|
+
LITERAL: Regexp
|
|
35
|
+
|
|
36
|
+
# @rbs return: String
|
|
37
|
+
def driver: () -> String
|
|
38
|
+
|
|
39
|
+
# @rbs location: String
|
|
40
|
+
# @rbs return: Skyward::ORM::_Connection
|
|
41
|
+
def connect: (String location) -> Skyward::ORM::_Connection
|
|
42
|
+
|
|
43
|
+
# Each connection to :memory: opens its own empty database, so there can be
|
|
44
|
+
# only the one.
|
|
45
|
+
# @rbs location: String
|
|
46
|
+
# @rbs size: Integer
|
|
47
|
+
# @rbs return: Integer
|
|
48
|
+
def pool_size: (String location, Integer size) -> Integer
|
|
49
|
+
|
|
50
|
+
# @rbs version: String
|
|
51
|
+
# @rbs return: void
|
|
52
|
+
def require_version: (String version) -> void
|
|
53
|
+
|
|
54
|
+
# @rbs (Integer _position) -> String
|
|
55
|
+
def placeholder: (Integer _position) -> String
|
|
56
|
+
|
|
57
|
+
# SQLite takes an OFFSET only after a LIMIT, and a negative one is no limit.
|
|
58
|
+
# @rbs return: String
|
|
59
|
+
def unlimited: () -> String
|
|
60
|
+
|
|
61
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
62
|
+
# @rbs return: String?
|
|
63
|
+
def sql_type: (Skyward::ORM::Tables::column_type type) -> String?
|
|
64
|
+
|
|
65
|
+
# An INTEGER PRIMARY KEY is SQLite's rowid, which numbers rows on its own.
|
|
66
|
+
# @rbs return: String?
|
|
67
|
+
def identity: () -> String?
|
|
68
|
+
|
|
69
|
+
# SQLite's ALTER TABLE can't change a column or a constraint, so a migration
|
|
70
|
+
# rebuilds the table instead.
|
|
71
|
+
# @rbs return: bool
|
|
72
|
+
def alters_in_place?: () -> bool
|
|
73
|
+
|
|
74
|
+
# SQLite takes only a literal as a default, unless the expression is in parentheses.
|
|
75
|
+
# @rbs expression: String
|
|
76
|
+
# @rbs return: String
|
|
77
|
+
def default_expression: (String expression) -> String
|
|
78
|
+
|
|
79
|
+
# SQLite stores a value by its column's affinity, which it reads from the
|
|
80
|
+
# declared type, so any declared type with the same affinity is compatible.
|
|
81
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
82
|
+
# @rbs sql_type: String
|
|
83
|
+
# @rbs return: bool
|
|
84
|
+
def compatible?: (Skyward::ORM::Tables::column_type type, String sql_type) -> bool
|
|
85
|
+
|
|
86
|
+
# @rbs value: untyped
|
|
87
|
+
# @rbs return: untyped
|
|
88
|
+
def encode: (untyped value) -> untyped
|
|
89
|
+
|
|
90
|
+
# @rbs type: Skyward::ORM::Tables::column_type
|
|
91
|
+
# @rbs value: untyped
|
|
92
|
+
# @rbs return: untyped
|
|
93
|
+
def decode: (Skyward::ORM::Tables::column_type type, untyped value) -> untyped
|
|
94
|
+
|
|
95
|
+
# @rbs (Skyward::ORM::_Connection connection) -> Array[Skyward::ORM::Catalog::Table]
|
|
96
|
+
def tables: (Skyward::ORM::_Connection connection) -> Array[Skyward::ORM::Catalog::Table]
|
|
97
|
+
|
|
98
|
+
# Foreign keys go off first, as SQLite's procedure for changing a table says,
|
|
99
|
+
# so dropping a table the migration rebuilds doesn't cascade to the rows that
|
|
100
|
+
# refer to it, and inside a transaction the PRAGMA does nothing. BEGIN
|
|
101
|
+
# IMMEDIATE takes the write lock as the transaction begins rather than at its
|
|
102
|
+
# first write, so a second migrator waits there, and then sees what the first ran.
|
|
103
|
+
# @rbs return: String
|
|
104
|
+
def begin_migration: () -> String
|
|
105
|
+
|
|
106
|
+
# @rbs (Skyward::ORM::_Connection connection) -> Array[String]
|
|
107
|
+
def foreign_key_violations: (Skyward::ORM::_Connection connection) -> Array[String]
|
|
108
|
+
|
|
109
|
+
# @rbs return: String
|
|
110
|
+
def end_migration: () -> String
|
|
111
|
+
|
|
112
|
+
# The code says which kind of constraint failed. The message names the
|
|
113
|
+
# columns of a unique or not-null one, and the name of a check, and the rest
|
|
114
|
+
# comes from the schema, from the table written, or from every table when
|
|
115
|
+
# raw SQL doesn't say which it writes.
|
|
116
|
+
# @rbs error: StandardError
|
|
117
|
+
# @rbs tables: Array[Skyward::ORM::Catalog::Table]
|
|
118
|
+
# @rbs table: Symbol?
|
|
119
|
+
# @rbs return: Skyward::ORM::Violation?
|
|
120
|
+
def violation: (StandardError error, Array[Skyward::ORM::Catalog::Table] tables, Symbol? table) -> Skyward::ORM::Violation?
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
# @rbs sql_type: String
|
|
125
|
+
# @rbs return: Symbol
|
|
126
|
+
def affinity: (String sql_type) -> Symbol
|
|
127
|
+
|
|
128
|
+
# @rbs rows: Array[Array[untyped]]
|
|
129
|
+
# @rbs return: Array[Skyward::ORM::Catalog::Index]
|
|
130
|
+
def indexes: (Array[Array[untyped]] rows) -> Array[Skyward::ORM::Catalog::Index]
|
|
131
|
+
|
|
132
|
+
# SQLite reads a default back without the parentheses an expression was
|
|
133
|
+
# written in, so they go back on, as a migration writes them.
|
|
134
|
+
# @rbs default: String?
|
|
135
|
+
# @rbs return: String?
|
|
136
|
+
def default: (String? default) -> String?
|
|
137
|
+
|
|
138
|
+
# SQLite names a unique index on expressions rather than its columns.
|
|
139
|
+
# @rbs message: String
|
|
140
|
+
# @rbs tables: Array[Skyward::ORM::Catalog::Table]
|
|
141
|
+
# @rbs return: Skyward::ORM::Violation
|
|
142
|
+
def unique: (String message, Array[Skyward::ORM::Catalog::Table] tables) -> Skyward::ORM::Violation
|
|
143
|
+
|
|
144
|
+
# @rbs message: String
|
|
145
|
+
# @rbs tables: Array[Skyward::ORM::Catalog::Table]
|
|
146
|
+
# @rbs table: Symbol?
|
|
147
|
+
# @rbs return: Skyward::ORM::Violation
|
|
148
|
+
def check: (String message, Array[Skyward::ORM::Catalog::Table] tables, Symbol? table) -> Skyward::ORM::Violation
|
|
149
|
+
|
|
150
|
+
# SQLite's message names no key at all, so it's the one key the table has
|
|
151
|
+
# or that refers to it. With more than one, it can't say which.
|
|
152
|
+
# @rbs message: String
|
|
153
|
+
# @rbs tables: Array[Skyward::ORM::Catalog::Table]
|
|
154
|
+
# @rbs table: Symbol?
|
|
155
|
+
# @rbs return: Skyward::ORM::Violation
|
|
156
|
+
def foreign_key: (String message, Array[Skyward::ORM::Catalog::Table] tables, Symbol? table) -> Skyward::ORM::Violation
|
|
157
|
+
|
|
158
|
+
# SQLite names them as table.column: "UNIQUE constraint failed: todos.list_id, todos.title".
|
|
159
|
+
# @rbs message: String
|
|
160
|
+
# @rbs return: [Symbol, Array[Symbol]]
|
|
161
|
+
def failed_columns: (String message) -> [ Symbol, Array[Symbol] ]
|
|
162
|
+
|
|
163
|
+
# @rbs message: String
|
|
164
|
+
# @rbs return: String
|
|
165
|
+
def detail: (String message) -> String
|
|
166
|
+
end
|