skyward-orm 0.3.0 → 0.4.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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +200 -31
  3. data/lib/skyward/orm/adapters/postgresql.rb +140 -38
  4. data/lib/skyward/orm/adapters/sqlite/constraints.rb +18 -0
  5. data/lib/skyward/orm/adapters/sqlite.rb +130 -21
  6. data/lib/skyward/orm/adapters.rb +12 -2
  7. data/lib/skyward/orm/catalog/column.rb +2 -1
  8. data/lib/skyward/orm/cli/boot_file.rb +2 -2
  9. data/lib/skyward/orm/cli/migrate.rb +1 -1
  10. data/lib/skyward/orm/cli/migration.rb +1 -1
  11. data/lib/skyward/orm/cli/scaffold/source.rb +304 -0
  12. data/lib/skyward/orm/cli/scaffold.rb +70 -0
  13. data/lib/skyward/orm/cli/status.rb +5 -3
  14. data/lib/skyward/orm/commands.rb +12 -0
  15. data/lib/skyward/orm/connection/instrumented.rb +69 -0
  16. data/lib/skyward/orm/connection/session.rb +74 -5
  17. data/lib/skyward/orm/{connection/database → database}/schema_check.rb +20 -8
  18. data/lib/skyward/orm/{connection/database.rb → database.rb} +15 -15
  19. data/lib/skyward/orm/execution.rb +9 -0
  20. data/lib/skyward/orm/migrations/alter_table.rb +6 -2
  21. data/lib/skyward/orm/migrations/definitions.rb +7 -4
  22. data/lib/skyward/orm/migrations/diff.rb +154 -30
  23. data/lib/skyward/orm/migrations/rename_constraint.rb +8 -0
  24. data/lib/skyward/orm/migrations/runner.rb +13 -3
  25. data/lib/skyward/orm/migrations/script.rb +60 -20
  26. data/lib/skyward/orm/migrations/status.rb +32 -3
  27. data/lib/skyward/orm/migrations/summary.rb +3 -6
  28. data/lib/skyward/orm/migrations/versions.rb +1 -1
  29. data/lib/skyward/orm/migrations.rb +1 -1
  30. data/lib/skyward/orm/projection.rb +23 -4
  31. data/lib/skyward/orm/queries/clauses.rb +117 -32
  32. data/lib/skyward/orm/record.rb +23 -1
  33. data/lib/skyward/orm/{placeholders.rb → statements/placeholders.rb} +1 -1
  34. data/lib/skyward/orm/statements.rb +171 -30
  35. data/lib/skyward/orm/tables/column.rb +2 -1
  36. data/lib/skyward/orm/tables/column_types.rb +62 -15
  37. data/lib/skyward/orm/tables/declarations.rb +38 -10
  38. data/lib/skyward/orm/{members.rb → tables/members.rb} +1 -1
  39. data/lib/skyward/orm/tables/sources.rb +63 -0
  40. data/lib/skyward/orm/tables/validation.rb +12 -3
  41. data/lib/skyward/orm/tables/values.rb +115 -5
  42. data/lib/skyward/orm/tables.rb +2 -1
  43. data/lib/skyward/orm/transactional.rb +2 -2
  44. data/lib/skyward/orm/version.rb +1 -1
  45. data/lib/skyward/orm.rb +44 -10
  46. data/sig/generated/skyward/orm/adapters/postgresql.rbs +53 -14
  47. data/sig/generated/skyward/orm/adapters/sqlite/constraints.rbs +6 -0
  48. data/sig/generated/skyward/orm/adapters/sqlite.rbs +67 -7
  49. data/sig/generated/skyward/orm/adapters.rbs +3 -0
  50. data/sig/generated/skyward/orm/catalog/column.rbs +6 -4
  51. data/sig/generated/skyward/orm/cli/boot_file.rbs +4 -4
  52. data/sig/generated/skyward/orm/cli/migrate.rbs +2 -2
  53. data/sig/generated/skyward/orm/cli/migration.rbs +2 -2
  54. data/sig/generated/skyward/orm/cli/scaffold/source.rbs +147 -0
  55. data/sig/generated/skyward/orm/cli/scaffold.rbs +28 -0
  56. data/sig/generated/skyward/orm/cli/status.rbs +2 -2
  57. data/sig/generated/skyward/orm/connection/instrumented.rbs +45 -0
  58. data/sig/generated/skyward/orm/connection/session.rbs +40 -6
  59. data/sig/generated/skyward/orm/{connection/database → database}/schema_check.rbs +11 -4
  60. data/sig/generated/skyward/orm/{connection/database.rbs → database.rbs} +4 -5
  61. data/sig/generated/skyward/orm/execution.rbs +18 -0
  62. data/sig/generated/skyward/orm/migrations/alter_table.rbs +11 -5
  63. data/sig/generated/skyward/orm/migrations/definitions.rbs +2 -2
  64. data/sig/generated/skyward/orm/migrations/diff.rbs +77 -11
  65. data/sig/generated/skyward/orm/migrations/rename_constraint.rbs +16 -0
  66. data/sig/generated/skyward/orm/migrations/runner.rbs +5 -0
  67. data/sig/generated/skyward/orm/migrations/script.rbs +32 -8
  68. data/sig/generated/skyward/orm/migrations/status.rbs +15 -2
  69. data/sig/generated/skyward/orm/migrations/summary.rbs +0 -1
  70. data/sig/generated/skyward/orm/migrations/versions.rbs +2 -2
  71. data/sig/generated/skyward/orm/migrations.rbs +1 -1
  72. data/sig/generated/skyward/orm/projection.rbs +10 -2
  73. data/sig/generated/skyward/orm/queries/clauses.rbs +60 -24
  74. data/sig/generated/skyward/orm/record.rbs +8 -0
  75. data/sig/generated/skyward/orm/{placeholders.rbs → statements/placeholders.rbs} +2 -2
  76. data/sig/generated/skyward/orm/statements.rbs +83 -5
  77. data/sig/generated/skyward/orm/tables/column.rbs +6 -4
  78. data/sig/generated/skyward/orm/tables/column_types.rbs +18 -4
  79. data/sig/generated/skyward/orm/tables/declarations.rbs +15 -1
  80. data/sig/generated/skyward/orm/{members.rbs → tables/members.rbs} +2 -2
  81. data/sig/generated/skyward/orm/tables/sources.rbs +32 -0
  82. data/sig/generated/skyward/orm/tables/values.rbs +41 -1
  83. data/sig/generated/skyward/orm/tables.rbs +3 -1
  84. data/sig/generated/skyward/orm.rbs +6 -6
  85. data/sig/manual/pg.rbs +12 -0
  86. data/sig/manual/skyward/orm/cli/scaffold/source.rbs +3 -0
  87. data/sig/manual/skyward/orm/cli/scaffold.rbs +3 -0
  88. data/sig/manual/skyward/orm/database/schema_check.rbs +3 -0
  89. data/sig/manual/skyward/orm/statements/placeholders.rbs +3 -0
  90. data/sig/manual/skyward/orm/tables/members.rbs +3 -0
  91. data/sig/manual/skyward/orm/tables/sources.rbs +3 -0
  92. data/sig/manual/skyward/orm.rbs +32 -5
  93. metadata +43 -14
  94. data/sig/manual/skyward/orm/connection/database/schema_check.rbs +0 -3
  95. data/sig/manual/skyward/orm/members.rbs +0 -3
  96. data/sig/manual/skyward/orm/placeholders.rbs +0 -3
@@ -1,6 +1,9 @@
1
1
  # Generated from lib/skyward/orm/migrations/script.rb with RBS::Inline
2
2
 
3
3
  module Skyward::ORM::Migrations::Script
4
+ # The column types of a primary key the database numbers.
5
+ NUMBERED: Array[Skyward::ORM::Tables::column_type]
6
+
4
7
  # @rbs changes: Array[Skyward::ORM::Migrations::change]
5
8
  # @rbs adapter: Skyward::ORM::_Adapter
6
9
  # @rbs return: String
@@ -8,6 +11,14 @@ module Skyward::ORM::Migrations::Script
8
11
 
9
12
  private
10
13
 
14
+ # A rebuild makes the table from its class, which can't say how the database
15
+ # generates a column, and the catalog keeps only a generated column's
16
+ # expression, not whether it's STORED, so the rebuild can't carry one over.
17
+ # @rbs changes: Array[Skyward::ORM::Migrations::change]
18
+ # @rbs adapter: Skyward::ORM::_Adapter
19
+ # @rbs return: void
20
+ def refuse_rebuilding_generated: (Array[Skyward::ORM::Migrations::change] changes, Skyward::ORM::_Adapter adapter) -> void
21
+
11
22
  # @rbs change: Skyward::ORM::Migrations::change
12
23
  # @rbs adapter: Skyward::ORM::_Adapter
13
24
  # @rbs return: String
@@ -39,11 +50,12 @@ module Skyward::ORM::Migrations::Script
39
50
  # @rbs return: String
40
51
  def backward: (Skyward::ORM::Migrations::AlterTable change, Skyward::ORM::Migrations::edit edit) -> String
41
52
 
42
- # SQLite rebuilds the table as its class has it: create the new one, copy
43
- # the rows of each column it keeps, drop the old one, rename the new one and
44
- # recreate its indexes. Dropping a table another one references would run
45
- # that one's ON DELETE, so `skyward migrate` turns SQLite's foreign keys off
46
- # around each migration, and checks them before it commits.
53
+ # SQLite rebuilds the table as its class has it, with what it keeps that the
54
+ # class can't declare: create the new one, copy the rows of each column it
55
+ # keeps, drop the old one, rename the new one and recreate its indexes.
56
+ # Dropping a table another one references would run that one's ON DELETE,
57
+ # so `skyward migrate` turns SQLite's foreign keys off around each
58
+ # migration, and checks them before it commits.
47
59
  # @rbs change: Skyward::ORM::Migrations::AlterTable
48
60
  # @rbs adapter: Skyward::ORM::_Adapter
49
61
  # @rbs return: String
@@ -66,10 +78,16 @@ module Skyward::ORM::Migrations::Script
66
78
 
67
79
  # Columns line up as a person would write them. A generated key's type runs
68
80
  # on into its identity clause, so it doesn't set the width. A rebuild keeps
69
- # the type an untyped column has.
81
+ # the type an untyped column has, and the constraints the class can't declare.
70
82
  # @rbs (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns,
71
- # Skyward::ORM::_Adapter adapter, Symbol name, Hash[Symbol, Skyward::ORM::Catalog::Column] kept) -> String
72
- def create_table: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::_Adapter adapter, Symbol name, Hash[Symbol, Skyward::ORM::Catalog::Column] kept) -> String
83
+ # Skyward::ORM::_Adapter adapter, Symbol name, Hash[Symbol, Skyward::ORM::Catalog::Column] kept,
84
+ # Array[Skyward::ORM::Catalog::Constraint] undeclared) -> String
85
+ def create_table: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::_Adapter adapter, Symbol name, Hash[Symbol, Skyward::ORM::Catalog::Column] kept, Array[Skyward::ORM::Catalog::Constraint] undeclared) -> String
86
+
87
+ # SQLite can hold a constraint with no name.
88
+ # @rbs constraint: Skyward::ORM::Catalog::Constraint
89
+ # @rbs return: String
90
+ def table_constraint: (Skyward::ORM::Catalog::Constraint constraint) -> String
73
91
 
74
92
  # @rbs klass: singleton(Skyward::ORM::Record)
75
93
  # @rbs return: String
@@ -133,6 +151,12 @@ module Skyward::ORM::Migrations::Script
133
151
  # @rbs return: String
134
152
  def drop_constraint: (Symbol table, Skyward::ORM::Catalog::Constraint constraint) -> String
135
153
 
154
+ # @rbs table: Symbol
155
+ # @rbs from: String
156
+ # @rbs to: String
157
+ # @rbs return: String
158
+ def rename_constraint: (Symbol table, String from, String to) -> String
159
+
136
160
  # The rows a table already has need a value for a new required column.
137
161
  # @rbs klass: singleton(Skyward::ORM::Record)
138
162
  # @rbs column: Skyward::ORM::Tables::Column
@@ -22,15 +22,24 @@ module Skyward::ORM::Migrations::Status
22
22
  # @rbs return: Array[Symbol]
23
23
  def unowned: (Array[Skyward::ORM::Catalog::Table] tables, Array[singleton(Skyward::ORM::Record)] classes) -> Array[Symbol]
24
24
 
25
+ # Each class whose table has what the class can't declare, with the name of
26
+ # each such index and constraint. SQLite can hold a constraint with no name.
27
+ # @rbs classes: Array[singleton(Skyward::ORM::Record)]
28
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
29
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
30
+ # @rbs return: Array[[singleton(Skyward::ORM::Record), Array[String]]]
31
+ def kept: (Array[singleton(Skyward::ORM::Record)] classes, Skyward::ORM::Tables::ColumnTypes column_types, Array[Skyward::ORM::Catalog::Table] tables) -> Array[[ singleton(Skyward::ORM::Record), Array[String] ]]
32
+
25
33
  # @rbs migrations: Array[[String, state]]
26
34
  # @rbs changes: Array[Skyward::ORM::Migrations::change]
27
35
  # @rbs unowned: Array[Symbol]
28
36
  # @rbs return: bool
29
37
  def clean?: (Array[[ String, state ]] migrations, Array[Skyward::ORM::Migrations::change] changes, Array[Symbol] unowned) -> bool
30
38
 
31
- # @rbs (Array[[String, state]] migrations, Array[Skyward::ORM::Migrations::change] changes, Array[Symbol] unowned,
39
+ # @rbs (Array[[String, state]] migrations, Array[Skyward::ORM::Migrations::change] changes,
40
+ # Array[[singleton(Skyward::ORM::Record), Array[String]]] kept, Array[Symbol] unowned,
32
41
  # Skyward::ORM::_Adapter adapter) -> String
33
- def text: (Array[[ String, state ]] migrations, Array[Skyward::ORM::Migrations::change] changes, Array[Symbol] unowned, Skyward::ORM::_Adapter adapter) -> String
42
+ def text: (Array[[ String, state ]] migrations, Array[Skyward::ORM::Migrations::change] changes, Array[[ singleton(Skyward::ORM::Record), Array[String] ]] kept, Array[Symbol] unowned, Skyward::ORM::_Adapter adapter) -> String
34
43
 
35
44
  private
36
45
 
@@ -43,6 +52,10 @@ module Skyward::ORM::Migrations::Status
43
52
  # @rbs return: String
44
53
  def listing: (Array[[ String, state ]] migrations) -> String
45
54
 
55
+ # @rbs kept: Array[[singleton(Skyward::ORM::Record), Array[String]]]
56
+ # @rbs return: String
57
+ def kept_text: (Array[[ singleton(Skyward::ORM::Record), Array[String] ]] kept) -> String
58
+
46
59
  # @rbs unowned: Array[Symbol]
47
60
  # @rbs return: String
48
61
  def unowned_text: (Array[Symbol] unowned) -> String
@@ -43,7 +43,6 @@ module Skyward::ORM::Migrations::Summary
43
43
  # @rbs return: String
44
44
  def constraint: (Skyward::ORM::Catalog::Constraint constraint) -> String
45
45
 
46
- # An index on an expression has no columns to name.
47
46
  # @rbs index: Skyward::ORM::Catalog::Index
48
47
  # @rbs return: String
49
48
  def index: (Skyward::ORM::Catalog::Index index) -> String
@@ -5,7 +5,7 @@ module Skyward::ORM::Migrations::Versions
5
5
  # never been migrated doesn't have the table yet.
6
6
  TABLE: Symbol
7
7
 
8
- # @rbs database: Skyward::ORM::Connection::Database
8
+ # @rbs database: Skyward::ORM::Database
9
9
  # @rbs return: Hash[String, String]
10
- def checksums: (Skyward::ORM::Connection::Database database) -> Hash[String, String]
10
+ def checksums: (Skyward::ORM::Database database) -> Hash[String, String]
11
11
  end
@@ -3,5 +3,5 @@
3
3
  module Skyward::ORM::Migrations
4
4
  type change = CreateTable | AlterTable
5
5
 
6
- type edit = AddColumn | DropColumn | RenameColumn | ChangeType | ChangeNullable | ChangeDefault | AddConstraint | DropConstraint | AddIndex | DropIndex
6
+ type edit = AddColumn | DropColumn | RenameColumn | ChangeType | ChangeNullable | ChangeDefault | AddConstraint | DropConstraint | RenameConstraint | AddIndex | DropIndex
7
7
  end
@@ -12,6 +12,14 @@ class Skyward::ORM::Projection[R]
12
12
  # @rbs return: R
13
13
  def insert!: (**untyped values) -> R
14
14
 
15
+ # @rbs rows: Array[Hash[Symbol, untyped]]
16
+ # @rbs return: Array[R] | Skyward::ORM::Violation
17
+ def insert_all: (Array[Hash[Symbol, untyped]] rows) -> (Array[R] | Skyward::ORM::Violation)
18
+
19
+ # @rbs rows: Array[Hash[Symbol, untyped]]
20
+ # @rbs return: Array[R]
21
+ def insert_all!: (Array[Hash[Symbol, untyped]] rows) -> Array[R]
22
+
15
23
  # @rbs **values: untyped
16
24
  # @rbs return: Array[R] | Skyward::ORM::Violation
17
25
  def update: (**untyped values) -> (Array[R] | Skyward::ORM::Violation)
@@ -28,8 +36,8 @@ class Skyward::ORM::Projection[R]
28
36
 
29
37
  private
30
38
 
31
- # An INSERT writes one row and takes none of a query's clauses, so the query
32
- # can only say what comes back.
39
+ # An INSERT takes none of a query's clauses, so the query can only say what
40
+ # comes back.
33
41
  # @rbs return: void
34
42
  def require_insertable: () -> void
35
43
 
@@ -12,8 +12,12 @@ module Skyward::ORM::Queries::Clauses[R]
12
12
 
13
13
  type scope = :all | :start | :narrowed
14
14
 
15
+ type parts = [ singleton(Skyward::ORM::Record), Array[Join], scope, Array[condition], Array[[ Symbol, direction ]], Array[Symbol], Integer?, Integer? ]
16
+
15
17
  DIRECTIONS: Array[direction]
16
18
 
19
+ COUNT: Skyward::ORM::Tables::Column
20
+
17
21
  class Comparison < Data
18
22
  attr_reader column(): Symbol
19
23
 
@@ -165,6 +169,10 @@ module Skyward::ORM::Queries::Clauses[R]
165
169
  # @rbs return: self
166
170
  def offset: (Integer count) -> self
167
171
 
172
+ # @rbs other: Skyward::ORM::Query[untyped]
173
+ # @rbs return: self
174
+ def merge: (Skyward::ORM::Query[untyped] other) -> self
175
+
168
176
  # Steep ties the row class to S only through its new, so the query keeps it
169
177
  # as the Class it is.
170
178
  # @rbs [S] (Skyward::ORM::_Row[S] row, **String expressions) -> Skyward::ORM::Projection[S]
@@ -200,6 +208,11 @@ module Skyward::ORM::Queries::Clauses[R]
200
208
  # @rbs return: [String, Array[untyped]]
201
209
  def to_sql: () -> [ String, Array[untyped] ]
202
210
 
211
+ # rbs-inline writes a protected method as public, so Steep would let an app
212
+ # call this, though Ruby won't.
213
+ # @rbs return: parts
214
+ def parts: () -> parts
215
+
203
216
  private
204
217
 
205
218
  # Steep can't tie the class it builds to self, or the row class to S, so
@@ -223,6 +236,22 @@ module Skyward::ORM::Queries::Clauses[R]
223
236
  # @rbs return: Join
224
237
  def joined: (String keyword, singleton(Skyward::ORM::Record) table, Hash[Symbol, Symbol] on) -> Join
225
238
 
239
+ # @rbs other: untyped
240
+ # @rbs return: void
241
+ def require_query: (untyped other) -> void
242
+
243
+ # Two scopes that each join a table the same way compose, so an identical
244
+ # join is kept once.
245
+ # @rbs joins: Array[Join]
246
+ # @rbs return: Array[Join]
247
+ def merged_joins: (Array[Join] joins) -> Array[Join]
248
+
249
+ # Merging only ever narrows, so every row may be changed only when both
250
+ # queries said so with an explicit all.
251
+ # @rbs scope: scope
252
+ # @rbs return: scope
253
+ def merged_scope: (scope scope) -> scope
254
+
226
255
  # @rbs sql: String?
227
256
  # @rbs values: Array[untyped]
228
257
  # @rbs conditions: Hash[Symbol, untyped]
@@ -258,17 +287,17 @@ module Skyward::ORM::Queries::Clauses[R]
258
287
  # @rbs return: void
259
288
  def require_members: (Class row, Hash[Symbol, String] expressions) -> void
260
289
 
261
- # @rbs database: Skyward::ORM::Connection::Database
290
+ # @rbs database: Skyward::ORM::Database
262
291
  # @rbs orders: Array[[Symbol, direction]]
263
292
  # @rbs limit: Integer?
264
293
  # @rbs return: [String, Array[untyped]]
265
- def statement: (Skyward::ORM::Connection::Database database, Array[[ Symbol, direction ]] orders, Integer? limit) -> [ String, Array[untyped] ]
294
+ def statement: (Skyward::ORM::Database database, Array[[ Symbol, direction ]] orders, Integer? limit) -> [ String, Array[untyped] ]
266
295
 
267
- # @rbs database: Skyward::ORM::Connection::Database
296
+ # @rbs database: Skyward::ORM::Database
268
297
  # @rbs orders: Array[[Symbol, direction]]
269
298
  # @rbs limit: Integer?
270
299
  # @rbs return: [String, Array[untyped]]
271
- def from: (Skyward::ORM::Connection::Database database, Array[[ Symbol, direction ]] orders, Integer? limit) -> [ String, Array[untyped] ]
300
+ def from: (Skyward::ORM::Database database, Array[[ Symbol, direction ]] orders, Integer? limit) -> [ String, Array[untyped] ]
272
301
 
273
302
  # @rbs join: Join
274
303
  # @rbs return: String
@@ -276,57 +305,58 @@ module Skyward::ORM::Queries::Clauses[R]
276
305
 
277
306
  # An UPDATE binds its SET values first, so its WHERE's numbered placeholders
278
307
  # start after them.
279
- # @rbs database: Skyward::ORM::Connection::Database
308
+ # @rbs database: Skyward::ORM::Database
280
309
  # @rbs position: Integer
281
310
  # @rbs return: [String?, Array[untyped]]
282
- def filter: (Skyward::ORM::Connection::Database database, Integer position) -> [ String?, Array[untyped] ]
311
+ def filter: (Skyward::ORM::Database database, Integer position) -> [ String?, Array[untyped] ]
283
312
 
284
- # @rbs database: Skyward::ORM::Connection::Database
313
+ # @rbs database: Skyward::ORM::Database
285
314
  # @rbs conditions: Array[condition]
286
315
  # @rbs position: Integer
287
316
  # @rbs return: [String, Array[untyped]]
288
- def conjunction: (Skyward::ORM::Connection::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
317
+ def conjunction: (Skyward::ORM::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
289
318
 
290
- # @rbs database: Skyward::ORM::Connection::Database
319
+ # @rbs database: Skyward::ORM::Database
291
320
  # @rbs condition: condition
292
321
  # @rbs position: Integer
293
322
  # @rbs return: [String, Array[untyped]]
294
- def render: (Skyward::ORM::Connection::Database database, condition condition, Integer position) -> [ String, Array[untyped] ]
323
+ def render: (Skyward::ORM::Database database, condition condition, Integer position) -> [ String, Array[untyped] ]
295
324
 
296
- # @rbs database: Skyward::ORM::Connection::Database
325
+ # @rbs database: Skyward::ORM::Database
297
326
  # @rbs comparison: Comparison
298
327
  # @rbs position: Integer
299
328
  # @rbs return: [String, Array[untyped]]
300
- def comparison: (Skyward::ORM::Connection::Database database, Comparison comparison, Integer position) -> [ String, Array[untyped] ]
329
+ def comparison: (Skyward::ORM::Database database, Comparison comparison, Integer position) -> [ String, Array[untyped] ]
301
330
 
302
- # @rbs database: Skyward::ORM::Connection::Database
331
+ # @rbs database: Skyward::ORM::Database
303
332
  # @rbs fragment: Fragment
304
333
  # @rbs position: Integer
305
334
  # @rbs return: [String, Array[untyped]]
306
- def fragment: (Skyward::ORM::Connection::Database database, Fragment fragment, Integer position) -> [ String, Array[untyped] ]
335
+ def fragment: (Skyward::ORM::Database database, Fragment fragment, Integer position) -> [ String, Array[untyped] ]
307
336
 
308
337
  # NOT of an unknown is unknown, so a row whose column is NULL would be left
309
338
  # out, though it doesn't match. An untyped column may hold NULL, and an SQL
310
339
  # string's columns can't be known.
311
- # @rbs database: Skyward::ORM::Connection::Database
340
+ # @rbs database: Skyward::ORM::Database
312
341
  # @rbs conditions: Array[condition]
313
342
  # @rbs position: Integer
314
343
  # @rbs return: [String, Array[untyped]]
315
- def negation: (Skyward::ORM::Connection::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
344
+ def negation: (Skyward::ORM::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
316
345
 
317
- # @rbs database: Skyward::ORM::Connection::Database
346
+ # @rbs database: Skyward::ORM::Database
318
347
  # @rbs conditions: Array[condition]
319
348
  # @rbs position: Integer
320
349
  # @rbs return: [String, Array[untyped]]
321
- def alternative: (Skyward::ORM::Connection::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
350
+ def alternative: (Skyward::ORM::Database database, Array[condition] conditions, Integer position) -> [ String, Array[untyped] ]
322
351
 
323
352
  # PostgreSQL refuses an empty IN (), and IN never matches NULL.
324
- # @rbs database: Skyward::ORM::Connection::Database
353
+ # @rbs adapter: Skyward::ORM::_Adapter
354
+ # @rbs column: Skyward::ORM::Tables::Column
325
355
  # @rbs name: String
326
356
  # @rbs values: Array[untyped]
327
357
  # @rbs position: Integer
328
358
  # @rbs return: [String, Array[untyped]]
329
- def within: (Skyward::ORM::Connection::Database database, String name, Array[untyped] values, Integer position) -> [ String, Array[untyped] ]
359
+ def within: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::Column column, String name, Array[untyped] values, Integer position) -> [ String, Array[untyped] ]
330
360
 
331
361
  # Steep can't tie the row class to R, so the rows are untyped here and each
332
362
  # public method types them.
@@ -338,9 +368,15 @@ module Skyward::ORM::Queries::Clauses[R]
338
368
  # @rbs return: Array[singleton(Skyward::ORM::Record)]
339
369
  def tables: () -> Array[singleton(Skyward::ORM::Record)]
340
370
 
341
- # @rbs database: Skyward::ORM::Connection::Database
371
+ # A table that's in a query twice needs an alias to tell the two apart,
372
+ # which a query can't give it.
373
+ # @rbs table: singleton(Skyward::ORM::Record)
374
+ # @rbs return: bool
375
+ def present?: (singleton(Skyward::ORM::Record) table) -> bool
376
+
377
+ # @rbs database: Skyward::ORM::Database
342
378
  # @rbs return: void
343
- def prepare: (Skyward::ORM::Connection::Database database) -> void
379
+ def prepare: (Skyward::ORM::Database database) -> void
344
380
 
345
381
  # Once a query has a join, a column's name could be in more than one table,
346
382
  # so each is qualified with its own.
@@ -358,9 +394,9 @@ module Skyward::ORM::Queries::Clauses[R]
358
394
 
359
395
  # @rbs method: Symbol
360
396
  # @rbs sql: String
361
- # @rbs values: Array[untyped]
397
+ # @rbs set: Array[untyped]
362
398
  # @rbs return: [String, Array[untyped]]
363
- def changing: (Symbol method, String sql, Array[untyped] values) -> [ String, Array[untyped] ]
399
+ def changing: (Symbol method, String sql, Array[untyped] set) -> [ String, Array[untyped] ]
364
400
 
365
401
  # @rbs [T] (T | Skyward::ORM::Violation written) -> T
366
402
  def unviolated: [T] (T | Skyward::ORM::Violation written) -> T
@@ -58,6 +58,14 @@ class Skyward::ORM::Record
58
58
  # @rbs return: Integer
59
59
  def self.insert!: (**untyped values) -> Integer
60
60
 
61
+ # @rbs rows: Array[Hash[Symbol, untyped]]
62
+ # @rbs return: Integer | Skyward::ORM::Violation
63
+ def self.insert_all: (Array[Hash[Symbol, untyped]] rows) -> (Integer | Skyward::ORM::Violation)
64
+
65
+ # @rbs rows: Array[Hash[Symbol, untyped]]
66
+ # @rbs return: Integer
67
+ def self.insert_all!: (Array[Hash[Symbol, untyped]] rows) -> Integer
68
+
61
69
  # @rbs return: Array[Symbol]
62
70
  def self.members: () -> Array[Symbol]
63
71
 
@@ -1,6 +1,6 @@
1
- # Generated from lib/skyward/orm/placeholders.rb with RBS::Inline
1
+ # Generated from lib/skyward/orm/statements/placeholders.rb with RBS::Inline
2
2
 
3
- module Skyward::ORM::Placeholders
3
+ module Skyward::ORM::Statements::Placeholders
4
4
  # A ? in a string, a quoted name or a comment is the SQL's own, so those
5
5
  # match whole and are kept. SQL escapes a quote by doubling it, which reads
6
6
  # here as two strings side by side.
@@ -3,10 +3,36 @@
3
3
  module Skyward::ORM::Statements
4
4
  # @rbs adapter: Skyward::ORM::_Adapter
5
5
  # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
6
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
6
7
  # @rbs table: singleton(Skyward::ORM::Record)
7
8
  # @rbs values: Hash[Symbol, untyped]
8
9
  # @rbs return: [String, Array[untyped]]
9
- def insert: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> [ String, Array[untyped] ]
10
+ def insert: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::ColumnTypes column_types, Array[Skyward::ORM::Catalog::Table] tables, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> [ String, Array[untyped] ]
11
+
12
+ # @rbs adapter: Skyward::ORM::_Adapter
13
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
14
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
15
+ # @rbs table: singleton(Skyward::ORM::Record)
16
+ # @rbs rows: Array[Hash[Symbol, untyped]]
17
+ # @rbs return: [String, Array[untyped]]
18
+ def insert_all: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::ColumnTypes column_types, Array[Skyward::ORM::Catalog::Table] tables, singleton(Skyward::ORM::Record) table, Array[Hash[Symbol, untyped]] rows) -> [ String, Array[untyped] ]
19
+
20
+ # @rbs adapter: Skyward::ORM::_Adapter
21
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
22
+ # @rbs table: singleton(Skyward::ORM::Record)
23
+ # @rbs values: Hash[Symbol, untyped]
24
+ # @rbs return: Array[untyped]
25
+ def binds: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> Array[untyped]
26
+
27
+ # Only a column says a Hash is JSON, or an Array one value: bound to a ? in
28
+ # SQL, either is refused, since the driver would spread it across
29
+ # placeholders. And only a column says an Integer is a decimal, whose text
30
+ # SQLite compares, so 2 is bound as 2.0, as BigDecimal(2) is.
31
+ # @rbs adapter: Skyward::ORM::_Adapter
32
+ # @rbs column: Skyward::ORM::Tables::Column
33
+ # @rbs value: untyped
34
+ # @rbs return: untyped
35
+ def encode: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::Column column, untyped value) -> untyped
10
36
 
11
37
  # @rbs table: singleton(Skyward::ORM::Record)
12
38
  # @rbs columns: Array[Symbol]
@@ -20,10 +46,16 @@ module Skyward::ORM::Statements
20
46
  def require_conditions: (Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] conditions) -> void
21
47
 
22
48
  # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
49
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
23
50
  # @rbs table: singleton(Skyward::ORM::Record)
24
51
  # @rbs values: Hash[Symbol, untyped]
25
52
  # @rbs return: void
26
- def require_values: (Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> void
53
+ def require_values: (Skyward::ORM::Tables::ColumnTypes column_types, Array[Skyward::ORM::Catalog::Table] tables, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> void
54
+
55
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
56
+ # @rbs table: singleton(Skyward::ORM::Record)
57
+ # @rbs return: Hash[Symbol, Skyward::ORM::Tables::Column]
58
+ def by_name: (Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table) -> Hash[Symbol, Skyward::ORM::Tables::Column]
27
59
 
28
60
  # @rbs columns: Array[Symbol]
29
61
  # @rbs return: String
@@ -36,18 +68,64 @@ module Skyward::ORM::Statements
36
68
 
37
69
  private
38
70
 
71
+ # @rbs type: Skyward::ORM::Tables::column_type?
72
+ # @rbs value: untyped
73
+ # @rbs return: untyped
74
+ def exact: (Skyward::ORM::Tables::column_type? type, untyped value) -> untyped
75
+
76
+ # @rbs adapter: Skyward::ORM::_Adapter
77
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
78
+ # @rbs table: singleton(Skyward::ORM::Record)
79
+ # @rbs columns: Array[Symbol]
80
+ # @rbs rows: Array[Hash[Symbol, untyped]]
81
+ # @rbs return: [String, Array[untyped]]
82
+ def inserting: (Skyward::ORM::_Adapter adapter, Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Array[Symbol] columns, Array[Hash[Symbol, untyped]] rows) -> [ String, Array[untyped] ]
83
+
84
+ # @rbs table: singleton(Skyward::ORM::Record)
85
+ # @rbs columns: Array[Symbol]
86
+ # @rbs return: String?
87
+ def unknown: (singleton(Skyward::ORM::Record) table, Array[Symbol] columns) -> String?
88
+
89
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
90
+ # @rbs table: singleton(Skyward::ORM::Record)
91
+ # @rbs return: Array[Symbol]
92
+ def generated: (Array[Skyward::ORM::Catalog::Table] tables, singleton(Skyward::ORM::Record) table) -> Array[Symbol]
93
+
94
+ # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
95
+ # @rbs generated: Array[Symbol]
96
+ # @rbs table: singleton(Skyward::ORM::Record)
97
+ # @rbs values: Hash[Symbol, untyped]
98
+ # @rbs return: String?
99
+ def unwritable: (Skyward::ORM::Tables::ColumnTypes column_types, Array[Symbol] generated, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) -> String?
100
+
39
101
  # @rbs column_types: Skyward::ORM::Tables::ColumnTypes
40
102
  # @rbs table: singleton(Skyward::ORM::Record)
41
103
  # @rbs values: Hash[Symbol, untyped]
42
104
  # @rbs &: (Skyward::ORM::Tables::Column column, untyped value) -> String?
43
- # @rbs return: void
44
- def refuse: (Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) { (Skyward::ORM::Tables::Column column, untyped value) -> String? } -> void
105
+ # @rbs return: String?
106
+ def refusal: (Skyward::ORM::Tables::ColumnTypes column_types, singleton(Skyward::ORM::Record) table, Hash[Symbol, untyped] values) { (Skyward::ORM::Tables::Column column, untyped value) -> String? } -> String?
45
107
 
46
108
  # An untyped column's nullability is unknown, so it's left to the database,
47
109
  # like a column the class doesn't declare.
48
110
  # @rbs table: singleton(Skyward::ORM::Record)
49
111
  # @rbs columns: Array[Skyward::ORM::Tables::Column]
50
112
  # @rbs given: Array[Symbol]
113
+ # @rbs generated: Array[Symbol]
114
+ # @rbs subject: String
115
+ # @rbs return: void
116
+ def require_present: (singleton(Skyward::ORM::Record) table, Array[Skyward::ORM::Tables::Column] columns, Array[Symbol] given, Array[Symbol] generated, String subject) -> void
117
+
118
+ # Matched as sets, since each row's values are read in the first row's order.
119
+ # @rbs subject: String
120
+ # @rbs columns: Array[Symbol]
121
+ # @rbs given: Array[Symbol]
122
+ # @rbs return: void
123
+ def require_alike: (String subject, Array[Symbol] columns, Array[Symbol] given) -> void
124
+
125
+ # @rbs adapter: Skyward::ORM::_Adapter
126
+ # @rbs table: singleton(Skyward::ORM::Record)
127
+ # @rbs rows: Integer
128
+ # @rbs columns: Integer
51
129
  # @rbs return: void
52
- def require_present: (singleton(Skyward::ORM::Record) table, Array[Skyward::ORM::Tables::Column] columns, Array[Symbol] given) -> void
130
+ def require_bindable: (Skyward::ORM::_Adapter adapter, singleton(Skyward::ORM::Record) table, Integer rows, Integer columns) -> void
53
131
  end
@@ -10,11 +10,13 @@ module Skyward::ORM::Tables
10
10
 
11
11
  attr_reader symbols(): Array[Symbol]
12
12
 
13
- def self.new: (Symbol name, column_type type, bool nullable, Array[Symbol] symbols) -> instance
14
- | (name: Symbol, type: column_type, nullable: bool, symbols: Array[Symbol]) -> instance
13
+ attr_reader element(): column_type?
15
14
 
16
- def self.members: () -> [ :name, :type, :nullable, :symbols ]
15
+ def self.new: (Symbol name, column_type type, bool nullable, Array[Symbol] symbols, column_type? element) -> instance
16
+ | (name: Symbol, type: column_type, nullable: bool, symbols: Array[Symbol], element: column_type?) -> instance
17
17
 
18
- def members: () -> [ :name, :type, :nullable, :symbols ]
18
+ def self.members: () -> [ :name, :type, :nullable, :symbols, :element ]
19
+
20
+ def members: () -> [ :name, :type, :nullable, :symbols, :element ]
19
21
  end
20
22
  end
@@ -9,6 +9,13 @@ class Skyward::ORM::Tables::ColumnTypes
9
9
 
10
10
  COLUMN_TYPES: String
11
11
 
12
+ ELEMENTS: Array[Skyward::Core::Types::scalar]
13
+
14
+ ELEMENT_TYPES: String
15
+
16
+ # The aliases Skyward ORM declares, for its reader to keep as the column type each names.
17
+ REFINEMENTS: Hash[String, Skyward::ORM::Tables::refinement]
18
+
12
19
  # @rbs reader: Skyward::Core::Types::Reader
13
20
  # @rbs return: void
14
21
  def initialize: (Skyward::Core::Types::Reader reader) -> void
@@ -28,12 +35,19 @@ class Skyward::ORM::Tables::ColumnTypes
28
35
  # @rbs name: Symbol
29
36
  # @rbs returned: RBS::Types::t
30
37
  # @rbs written: String
31
- # @rbs return: Skyward::ORM::Tables::Column | String
32
- def read: (Symbol name, RBS::Types::t returned, String written) -> (Skyward::ORM::Tables::Column | String)
38
+ # @rbs return: Skyward::ORM::Tables::Column | [String, String?]
39
+ def read: (Symbol name, RBS::Types::t returned, String written) -> (Skyward::ORM::Tables::Column | [ String, String? ])
33
40
 
34
41
  # @rbs name: Symbol
35
42
  # @rbs read: Skyward::Core::Types::result
36
43
  # @rbs written: String
37
- # @rbs return: Skyward::ORM::Tables::Column | String
38
- def column: (Symbol name, Skyward::Core::Types::result read, String written) -> (Skyward::ORM::Tables::Column | String)
44
+ # @rbs return: Skyward::ORM::Tables::Column | [String, String?]
45
+ def column: (Symbol name, Skyward::Core::Types::result read, String written) -> (Skyward::ORM::Tables::Column | [ String, String? ])
46
+
47
+ # @rbs name: Symbol
48
+ # @rbs item: Skyward::Core::Types::t
49
+ # @rbs nullable: bool
50
+ # @rbs written: String
51
+ # @rbs return: Skyward::ORM::Tables::Column | [String, String?]
52
+ def array: (Symbol name, Skyward::Core::Types::t item, bool nullable, String written) -> (Skyward::ORM::Tables::Column | [ String, String? ])
39
53
  end
@@ -6,11 +6,20 @@ module Skyward::ORM::Tables::Declarations : Class
6
6
 
7
7
  ON_DELETE: Array[Skyward::ORM::Tables::on_delete]
8
8
 
9
+ @locations: Hash[[ Symbol, Symbol ], [ String, Integer ]]?
10
+
9
11
  @schema: Skyward::ORM::Tables::Schema?
10
12
 
11
13
  # @rbs return: Skyward::ORM::Tables::Schema
12
14
  def schema: () -> Skyward::ORM::Tables::Schema
13
15
 
16
+ # The schema is compared as a value, so where each name was declared is kept
17
+ # beside it, by the declaration and the column or table it names.
18
+ # @rbs declaration: Symbol
19
+ # @rbs name: Symbol
20
+ # @rbs return: [String, Integer]?
21
+ def declared_at: (Symbol declaration, Symbol name) -> [ String, Integer ]?
22
+
14
23
  # @rbs return: Symbol
15
24
  def table_name: () -> Symbol
16
25
 
@@ -53,9 +62,14 @@ module Skyward::ORM::Tables::Declarations : Class
53
62
 
54
63
  private
55
64
 
65
+ # Only a declaration calls this, so its caller's caller is the class body.
66
+ # An anonymous class, from Class.new, keeps no location, and eval'd code has
67
+ # no file to point at.
68
+ # @rbs declaration: Symbol
69
+ # @rbs names: Array[Symbol]
56
70
  # @rbs **changes: untyped
57
71
  # @rbs return: void
58
- def declare: (**untyped changes) -> void
72
+ def declare: (Symbol declaration, Array[Symbol] names, **untyped changes) -> void
59
73
 
60
74
  # @rbs declaration: Symbol
61
75
  # @rbs arguments: Array[untyped]
@@ -1,6 +1,6 @@
1
- # Generated from lib/skyward/orm/members.rb with RBS::Inline
1
+ # Generated from lib/skyward/orm/tables/members.rb with RBS::Inline
2
2
 
3
- module Skyward::ORM::Members
3
+ module Skyward::ORM::Tables::Members
4
4
  KEYWORDS: Array[Symbol]
5
5
 
6
6
  # @rbs row: Class
@@ -0,0 +1,32 @@
1
+ # Generated from lib/skyward/orm/tables/sources.rb with RBS::Inline
2
+
3
+ module Skyward::ORM::Tables::Sources
4
+ # @rbs klass: singleton(Skyward::ORM::Record)
5
+ # @rbs declaration: Symbol
6
+ # @rbs name: Symbol
7
+ # @rbs return: Skyward::Core::Diagnostics::Spot?
8
+ def declaration: (singleton(Skyward::ORM::Record) klass, Symbol declaration, Symbol name) -> Skyward::Core::Diagnostics::Spot?
9
+
10
+ # A type in a hand-written .rbs leaves the reader's line with no type to
11
+ # point at, so the carets go under the column's name.
12
+ # @rbs klass: Class
13
+ # @rbs column: Symbol
14
+ # @rbs return: Skyward::Core::Diagnostics::Spot?
15
+ def reader: (Class klass, Symbol column) -> Skyward::Core::Diagnostics::Spot?
16
+
17
+ # Only a `class` keyword's line is pointed at, so a class from Class.new
18
+ # keeps its message even once a constant names it, as its declarations do.
19
+ # @rbs klass: Module
20
+ # @rbs return: Skyward::Core::Diagnostics::Spot?
21
+ def class_name: (Module klass) -> Skyward::Core::Diagnostics::Spot?
22
+
23
+ # @rbs message: String
24
+ # @rbs spots: Array[Skyward::Core::Diagnostics::Spot?]
25
+ # @rbs suggestion: String?
26
+ # @rbs return: String
27
+ def explain: (String message, Array[Skyward::Core::Diagnostics::Spot?] spots, ?String? suggestion) -> String
28
+
29
+ # @rbs problems: Array[String]
30
+ # @rbs return: String
31
+ def join: (Array[String] problems) -> String
32
+ end