masonite-framework-orm 3.0.1__py3-none-any.whl

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 (116) hide show
  1. masonite_framework_orm-3.0.1.dist-info/METADATA +87 -0
  2. masonite_framework_orm-3.0.1.dist-info/RECORD +116 -0
  3. masonite_framework_orm-3.0.1.dist-info/WHEEL +5 -0
  4. masonite_framework_orm-3.0.1.dist-info/entry_points.txt +3 -0
  5. masonite_framework_orm-3.0.1.dist-info/licenses/LICENSE +21 -0
  6. masonite_framework_orm-3.0.1.dist-info/top_level.txt +1 -0
  7. masoniteorm/__init__.py +1 -0
  8. masoniteorm/collection/Collection.py +605 -0
  9. masoniteorm/collection/__init__.py +1 -0
  10. masoniteorm/commands/CanOverrideConfig.py +16 -0
  11. masoniteorm/commands/CanOverrideOptionsDefault.py +22 -0
  12. masoniteorm/commands/Command.py +6 -0
  13. masoniteorm/commands/Entry.py +43 -0
  14. masoniteorm/commands/MakeMigrationCommand.py +57 -0
  15. masoniteorm/commands/MakeModelCommand.py +78 -0
  16. masoniteorm/commands/MakeModelDocstringCommand.py +37 -0
  17. masoniteorm/commands/MakeObserverCommand.py +54 -0
  18. masoniteorm/commands/MakeSeedCommand.py +54 -0
  19. masoniteorm/commands/MigrateCommand.py +46 -0
  20. masoniteorm/commands/MigrateFreshCommand.py +41 -0
  21. masoniteorm/commands/MigrateRefreshCommand.py +41 -0
  22. masoniteorm/commands/MigrateResetCommand.py +25 -0
  23. masoniteorm/commands/MigrateRollbackCommand.py +26 -0
  24. masoniteorm/commands/MigrateStatusCommand.py +51 -0
  25. masoniteorm/commands/SeedRunCommand.py +35 -0
  26. masoniteorm/commands/ShellCommand.py +205 -0
  27. masoniteorm/commands/__init__.py +18 -0
  28. masoniteorm/commands/stubs/create_migration.stub +20 -0
  29. masoniteorm/commands/stubs/create_seed.stub +9 -0
  30. masoniteorm/commands/stubs/model.stub +9 -0
  31. masoniteorm/commands/stubs/observer.stub +101 -0
  32. masoniteorm/commands/stubs/table_migration.stub +19 -0
  33. masoniteorm/config.py +123 -0
  34. masoniteorm/connections/BaseConnection.py +101 -0
  35. masoniteorm/connections/ConnectionFactory.py +59 -0
  36. masoniteorm/connections/ConnectionResolver.py +132 -0
  37. masoniteorm/connections/MSSQLConnection.py +176 -0
  38. masoniteorm/connections/MySQLConnection.py +232 -0
  39. masoniteorm/connections/PostgresConnection.py +225 -0
  40. masoniteorm/connections/SQLiteConnection.py +179 -0
  41. masoniteorm/connections/__init__.py +6 -0
  42. masoniteorm/exceptions.py +38 -0
  43. masoniteorm/expressions/__init__.py +1 -0
  44. masoniteorm/expressions/expressions.py +288 -0
  45. masoniteorm/factories/Factory.py +112 -0
  46. masoniteorm/factories/__init__.py +1 -0
  47. masoniteorm/helpers/__init__.py +0 -0
  48. masoniteorm/helpers/misc.py +22 -0
  49. masoniteorm/migrations/Migration.py +330 -0
  50. masoniteorm/migrations/__init__.py +1 -0
  51. masoniteorm/models/MigrationModel.py +9 -0
  52. masoniteorm/models/Model.py +1209 -0
  53. masoniteorm/models/Model.pyi +1366 -0
  54. masoniteorm/models/Pivot.py +5 -0
  55. masoniteorm/models/__init__.py +1 -0
  56. masoniteorm/observers/ObservesEvents.py +27 -0
  57. masoniteorm/observers/__init__.py +1 -0
  58. masoniteorm/pagination/BasePaginator.py +10 -0
  59. masoniteorm/pagination/LengthAwarePaginator.py +34 -0
  60. masoniteorm/pagination/SimplePaginator.py +28 -0
  61. masoniteorm/pagination/__init__.py +2 -0
  62. masoniteorm/providers/ORMProvider.py +39 -0
  63. masoniteorm/providers/__init__.py +1 -0
  64. masoniteorm/query/EagerRelation.py +42 -0
  65. masoniteorm/query/QueryBuilder.py +2486 -0
  66. masoniteorm/query/__init__.py +1 -0
  67. masoniteorm/query/grammars/BaseGrammar.py +1027 -0
  68. masoniteorm/query/grammars/MSSQLGrammar.py +194 -0
  69. masoniteorm/query/grammars/MySQLGrammar.py +238 -0
  70. masoniteorm/query/grammars/PostgresGrammar.py +213 -0
  71. masoniteorm/query/grammars/SQLiteGrammar.py +228 -0
  72. masoniteorm/query/grammars/__init__.py +4 -0
  73. masoniteorm/query/processors/MSSQLPostProcessor.py +58 -0
  74. masoniteorm/query/processors/MySQLPostProcessor.py +48 -0
  75. masoniteorm/query/processors/PostgresPostProcessor.py +49 -0
  76. masoniteorm/query/processors/SQLitePostProcessor.py +49 -0
  77. masoniteorm/query/processors/__init__.py +4 -0
  78. masoniteorm/relationships/BaseRelationship.py +161 -0
  79. masoniteorm/relationships/BelongsTo.py +124 -0
  80. masoniteorm/relationships/BelongsToMany.py +604 -0
  81. masoniteorm/relationships/HasMany.py +66 -0
  82. masoniteorm/relationships/HasManyThrough.py +269 -0
  83. masoniteorm/relationships/HasOne.py +111 -0
  84. masoniteorm/relationships/HasOneThrough.py +275 -0
  85. masoniteorm/relationships/MorphMany.py +152 -0
  86. masoniteorm/relationships/MorphOne.py +156 -0
  87. masoniteorm/relationships/MorphTo.py +111 -0
  88. masoniteorm/relationships/MorphToMany.py +108 -0
  89. masoniteorm/relationships/__init__.py +10 -0
  90. masoniteorm/schema/Blueprint.py +1161 -0
  91. masoniteorm/schema/Column.py +144 -0
  92. masoniteorm/schema/ColumnDiff.py +0 -0
  93. masoniteorm/schema/Constraint.py +5 -0
  94. masoniteorm/schema/ForeignKeyConstraint.py +28 -0
  95. masoniteorm/schema/Index.py +5 -0
  96. masoniteorm/schema/Schema.py +359 -0
  97. masoniteorm/schema/Table.py +94 -0
  98. masoniteorm/schema/TableDiff.py +86 -0
  99. masoniteorm/schema/__init__.py +3 -0
  100. masoniteorm/schema/platforms/MSSQLPlatform.py +367 -0
  101. masoniteorm/schema/platforms/MySQLPlatform.py +513 -0
  102. masoniteorm/schema/platforms/Platform.py +97 -0
  103. masoniteorm/schema/platforms/PostgresPlatform.py +551 -0
  104. masoniteorm/schema/platforms/SQLitePlatform.py +481 -0
  105. masoniteorm/schema/platforms/__init__.py +4 -0
  106. masoniteorm/scopes/BaseScope.py +6 -0
  107. masoniteorm/scopes/SoftDeleteScope.py +56 -0
  108. masoniteorm/scopes/SoftDeletesMixin.py +13 -0
  109. masoniteorm/scopes/TimeStampsMixin.py +12 -0
  110. masoniteorm/scopes/TimeStampsScope.py +47 -0
  111. masoniteorm/scopes/UUIDPrimaryKeyMixin.py +8 -0
  112. masoniteorm/scopes/UUIDPrimaryKeyScope.py +51 -0
  113. masoniteorm/scopes/__init__.py +8 -0
  114. masoniteorm/scopes/scope.py +15 -0
  115. masoniteorm/seeds/Seeder.py +42 -0
  116. masoniteorm/seeds/__init__.py +1 -0
@@ -0,0 +1,144 @@
1
+ class Column:
2
+ """Used for creating or modifying columns."""
3
+
4
+ def __init__(
5
+ self,
6
+ name,
7
+ column_type,
8
+ length=None,
9
+ values=None,
10
+ nullable=False,
11
+ default=None,
12
+ signed=None,
13
+ default_is_raw=False,
14
+ column_python_type=str,
15
+ ):
16
+ self.column_type = column_type
17
+ self.column_python_type = column_python_type
18
+ self.name = name
19
+ self.length = length
20
+ self.values = values or []
21
+ self.is_null = nullable
22
+ self._after = None
23
+ self.old_column = ""
24
+ self.default = default
25
+ self._signed = signed
26
+ self.default_is_raw = default_is_raw
27
+ self.primary = False
28
+ self.comment = None
29
+
30
+ def nullable(self):
31
+ """Sets this column to be nullable
32
+
33
+ Returns:
34
+ self
35
+ """
36
+ self.is_null = True
37
+ return self
38
+
39
+ def signed(self):
40
+ """Sets this column to be nullable
41
+
42
+ Returns:
43
+ self
44
+ """
45
+ self._signed = "signed"
46
+ return self
47
+
48
+ def unsigned(self):
49
+ """Sets this column to be nullable
50
+
51
+ Returns:
52
+ self
53
+ """
54
+ self._signed = "unsigned"
55
+ return self
56
+
57
+ def not_nullable(self):
58
+ """Sets this column to be not nullable
59
+
60
+ Returns:
61
+ self
62
+ """
63
+ self.is_null = False
64
+ return self
65
+
66
+ def set_as_primary(self):
67
+ self.primary = True
68
+
69
+ def rename(self, column):
70
+ """Renames this column to a new name
71
+
72
+ Arguments:
73
+ column {string} -- The old column name
74
+
75
+ Returns:
76
+ self
77
+ """
78
+ self.old_column = column
79
+ return self
80
+
81
+ def after(self, after):
82
+ """Sets the column that this new column should be created after.
83
+
84
+ This is useful for setting the location of the new column in the table schema.
85
+
86
+ Arguments:
87
+ after {string} -- The column that this new column should be created after
88
+
89
+ Returns:
90
+ self
91
+ """
92
+ self._after = after
93
+ return self
94
+
95
+ def get_after_column(self):
96
+ """Sets the column that this new column should be created after.
97
+
98
+ This is useful for setting the location of the new column in the table schema.
99
+
100
+ Arguments:
101
+ after {string} -- The column that this new column should be created after
102
+
103
+ Returns:
104
+ self
105
+ """
106
+ return self._after
107
+
108
+ def default(self, value, raw=False):
109
+ """Sets a default value for this column
110
+
111
+ Arguments:
112
+ value {string} -- A default value.
113
+ raw {bool} -- should the value be quoted
114
+
115
+ Returns:
116
+ self
117
+ """
118
+ self.default = value
119
+ self.default_is_raw = raw
120
+ return self
121
+
122
+ def change(self):
123
+ """Sets the schema to create a modify sql statement.
124
+
125
+ Returns:
126
+ self
127
+ """
128
+ self._action = "modify"
129
+ return self
130
+
131
+ def use_current(self):
132
+ """Sets the column to use a current timestamp.
133
+
134
+ Used for timestamp columns.
135
+
136
+ Returns:
137
+ self
138
+ """
139
+ self.default = "current"
140
+ return self
141
+
142
+ def add_comment(self, comment):
143
+ self.comment = comment
144
+ return self
File without changes
@@ -0,0 +1,5 @@
1
+ class Constraint:
2
+ def __init__(self, name, constraint_type, columns=None):
3
+ self.name = name
4
+ self.constraint_type = constraint_type
5
+ self.columns = columns or []
@@ -0,0 +1,28 @@
1
+ class ForeignKeyConstraint:
2
+ def __init__(self, column, foreign_table, foreign_column, name=None):
3
+ self.column = column
4
+ self.foreign_table = foreign_table
5
+ self.foreign_column = foreign_column
6
+ self.delete_action = None
7
+ self.update_action = None
8
+ self.constraint_name = name
9
+
10
+ def references(self, foreign_column):
11
+ self.foreign_column = foreign_column
12
+ return self
13
+
14
+ def on(self, foreign_table):
15
+ self.foreign_table = foreign_table
16
+ return self
17
+
18
+ def on_delete(self, action):
19
+ self.delete_action = action
20
+ return self
21
+
22
+ def on_update(self, action):
23
+ self.update_action = action
24
+ return self
25
+
26
+ def name(self, name):
27
+ self.constraint_name = name
28
+ return self
@@ -0,0 +1,5 @@
1
+ class Index:
2
+ def __init__(self, column, name, index_type):
3
+ self.column = column
4
+ self.name = name
5
+ self.index_type = index_type
@@ -0,0 +1,359 @@
1
+ from ..config import load_config
2
+ from ..exceptions import ConnectionNotRegistered
3
+ from .Blueprint import Blueprint
4
+ from .Table import Table
5
+ from .TableDiff import TableDiff
6
+
7
+
8
+ class Schema:
9
+ _default_string_length = "255"
10
+ _type_hints_map = {
11
+ "string": str,
12
+ "char": str,
13
+ "big_increments": int,
14
+ "integer": int,
15
+ "big_integer": int,
16
+ "tiny_integer": int,
17
+ "small_integer": int,
18
+ "medium_integer": int,
19
+ "integer_unsigned": int,
20
+ "big_integer_unsigned": int,
21
+ "tiny_integer_unsigned": int,
22
+ "small_integer_unsigned": int,
23
+ "medium_integer_unsigned": int,
24
+ "increments": int,
25
+ "uuid": str,
26
+ "binary": bytes,
27
+ "boolean": bool,
28
+ "decimal": float,
29
+ "double": float,
30
+ "enum": str,
31
+ "text": str,
32
+ "float": float,
33
+ "geometry": str, # ?
34
+ "json": dict,
35
+ "jsonb": bytes,
36
+ "inet": str,
37
+ "cidr": str,
38
+ "macaddr": str,
39
+ "long_text": str,
40
+ "point": str, # ?
41
+ "time": str, # or pendulum.DateTime
42
+ "timestamp": str, # or pendulum.DateTime
43
+ "date": str, # or pendulum.DateTime
44
+ "year": str,
45
+ "datetime": str, # or pendulum.DateTime
46
+ "tiny_increments": int,
47
+ "unsigned": int,
48
+ "unsigned_integer": int,
49
+ }
50
+
51
+ def __init__(
52
+ self,
53
+ dry=False,
54
+ connection="default",
55
+ connection_class=None,
56
+ platform=None,
57
+ grammar=None,
58
+ connection_details=None,
59
+ schema=None,
60
+ config_path=None,
61
+ ):
62
+ self._dry = dry
63
+ self.connection = connection
64
+ self.connection_class = connection_class
65
+ self._connection = None
66
+ self.grammar = grammar
67
+ self.platform = platform
68
+ self.connection_details = connection_details or {}
69
+ self._blueprint = None
70
+ self._sql = None
71
+ self.schema = schema
72
+ self.config_path = config_path
73
+
74
+ if not self.connection_class:
75
+ self.on(self.connection)
76
+
77
+ if not self.platform:
78
+ self.platform = self.connection_class.get_default_platform()
79
+
80
+ def on(self, connection_key):
81
+ """Change the connection from the default connection
82
+
83
+ Arguments:
84
+ connection {string} -- A connection string like 'mysql' or 'mssql'.
85
+ It will be made with the connection factory.
86
+
87
+ Returns:
88
+ cls
89
+ """
90
+ resolver = load_config(config_path=self.config_path).DB
91
+ self.connection_details = resolver.get_connection_details()
92
+ if connection_key == "default":
93
+ self.connection = self.connection_details.get("default")
94
+ else:
95
+ self.connection = connection_key
96
+
97
+ connection_detail = self.connection_details.get(self.connection)
98
+ if connection_detail:
99
+ self._connection_driver = connection_detail.get("driver")
100
+ else:
101
+ raise ConnectionNotRegistered(
102
+ f"Could not find the '{connection_key}' connection details"
103
+ )
104
+
105
+ self.connection_class = resolver.connection_factory.make(
106
+ self._connection_driver
107
+ )
108
+
109
+ return self
110
+
111
+ def dry(self):
112
+ """Whether the query should be executed. (default: {False})
113
+
114
+ Returns:
115
+ self
116
+ """
117
+ self._dry = True
118
+ return self
119
+
120
+ def create(self, table):
121
+ """Sets the table and returns the blueprint.
122
+
123
+ This should be used as a context manager.
124
+
125
+ Arguments:
126
+ table {string} -- The name of a table like 'users'
127
+
128
+ Returns:
129
+ masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object.
130
+ """
131
+ self._table = table
132
+
133
+ self._blueprint = Blueprint(
134
+ self.grammar,
135
+ connection=self.new_connection(),
136
+ table=Table(table),
137
+ action="create",
138
+ platform=self.platform,
139
+ schema=self.schema,
140
+ default_string_length=self._default_string_length,
141
+ dry=self._dry,
142
+ )
143
+
144
+ return self._blueprint
145
+
146
+ def create_table_if_not_exists(self, table):
147
+ self._table = table
148
+
149
+ self._blueprint = Blueprint(
150
+ self.grammar,
151
+ connection=self.new_connection(),
152
+ table=Table(table),
153
+ action="create_table_if_not_exists",
154
+ platform=self.platform,
155
+ schema=self.schema,
156
+ default_string_length=self._default_string_length,
157
+ dry=self._dry,
158
+ )
159
+
160
+ return self._blueprint
161
+
162
+ def table(self, table):
163
+ """Sets the table and returns the blueprint.
164
+
165
+ This should be used as a context manager.
166
+
167
+ Arguments:
168
+ table {string} -- The name of a table like 'users'
169
+
170
+ Returns:
171
+ masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object.
172
+ """
173
+ self._table = table
174
+
175
+ self._blueprint = Blueprint(
176
+ self.grammar,
177
+ connection=self.new_connection(),
178
+ table=TableDiff(table),
179
+ action="alter",
180
+ platform=self.platform,
181
+ schema=self.schema,
182
+ default_string_length=self._default_string_length,
183
+ dry=self._dry,
184
+ )
185
+
186
+ return self._blueprint
187
+
188
+ def get_connection_information(self):
189
+ return {
190
+ "host": self.connection_details.get(self.connection, {}).get(
191
+ "host"
192
+ ),
193
+ "database": self.connection_details.get(self.connection, {}).get(
194
+ "database"
195
+ ),
196
+ "user": self.connection_details.get(self.connection, {}).get(
197
+ "user"
198
+ ),
199
+ "port": self.connection_details.get(self.connection, {}).get(
200
+ "port"
201
+ ),
202
+ "password": self.connection_details.get(self.connection, {}).get(
203
+ "password"
204
+ ),
205
+ "prefix": self.connection_details.get(self.connection, {}).get(
206
+ "prefix"
207
+ ),
208
+ "options": self.connection_details.get(self.connection, {}).get(
209
+ "options", {}
210
+ ),
211
+ "full_details": self.connection_details.get(self.connection),
212
+ }
213
+
214
+ def new_connection(self):
215
+ if self._dry:
216
+ return
217
+
218
+ self._connection = (
219
+ self.connection_class(**self.get_connection_information())
220
+ .set_schema(self.schema)
221
+ .make_connection()
222
+ )
223
+
224
+ return self._connection
225
+
226
+ def has_column(self, table, column, query_only=False):
227
+ """Checks if the a table has a specific column
228
+
229
+ Arguments:
230
+ table {string} -- The name of a table like 'users'
231
+
232
+ Returns:
233
+ masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object.
234
+ """
235
+ sql = self.platform().compile_column_exists(table, column)
236
+
237
+ if self._dry:
238
+ self._sql = sql
239
+ return sql
240
+
241
+ return bool(self.new_connection().query(sql, ()))
242
+
243
+ def get_columns(self, table, dict=True):
244
+ table = self.platform().get_current_schema(
245
+ self.new_connection(), table, schema=self.get_schema()
246
+ )
247
+ result = {}
248
+ if dict:
249
+ for column in table.get_added_columns().items():
250
+ result.update({column[0]: column[1]})
251
+ return result
252
+ else:
253
+ return table.get_added_columns().items()
254
+
255
+ @classmethod
256
+ def set_default_string_length(cls, length):
257
+ cls._default_string_length = length
258
+ return cls
259
+
260
+ def drop_table(self, table, query_only=False):
261
+ sql = self.platform().compile_drop_table(table)
262
+
263
+ if self._dry:
264
+ self._sql = sql
265
+ return sql
266
+
267
+ return bool(self.new_connection().query(sql, ()))
268
+
269
+ def drop(self, *args, **kwargs):
270
+ return self.drop_table(*args, **kwargs)
271
+
272
+ def drop_table_if_exists(self, table, exists=False, query_only=False):
273
+ sql = self.platform().compile_drop_table_if_exists(table)
274
+
275
+ if self._dry:
276
+ self._sql = sql
277
+ return sql
278
+
279
+ return bool(self.new_connection().query(sql, ()))
280
+
281
+ def rename(self, table, new_name):
282
+ sql = self.platform().compile_rename_table(table, new_name)
283
+
284
+ if self._dry:
285
+ self._sql = sql
286
+ return sql
287
+
288
+ return bool(self.new_connection().query(sql, ()))
289
+
290
+ def truncate(self, table, foreign_keys=False):
291
+ sql = self.platform().compile_truncate(
292
+ table, foreign_keys=foreign_keys
293
+ )
294
+
295
+ if self._dry:
296
+ self._sql = sql
297
+ return sql
298
+
299
+ return bool(self.new_connection().query(sql, ()))
300
+
301
+ def get_schema(self):
302
+ """Gets the schema set on the migration class"""
303
+ return self.schema or self.get_connection_information().get(
304
+ "full_details"
305
+ ).get("schema")
306
+
307
+ def get_all_tables(self):
308
+ """Gets all tables in the database"""
309
+ sql = self.platform().compile_get_all_tables(
310
+ database=self.get_connection_information().get("database"),
311
+ schema=self.get_schema(),
312
+ )
313
+
314
+ if self._dry:
315
+ self._sql = sql
316
+ return sql
317
+
318
+ result = self.new_connection().query(sql, ())
319
+
320
+ return (
321
+ list(map(lambda t: list(t.values())[0], result)) if result else []
322
+ )
323
+
324
+ def has_table(self, table, query_only=False):
325
+ """Checks if the a database has a specific table
326
+ Arguments:
327
+ table {string} -- The name of a table like 'users'
328
+ Returns:
329
+ masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object.
330
+ """
331
+ sql = self.platform().compile_table_exists(
332
+ table,
333
+ database=self.get_connection_information().get("database"),
334
+ schema=self.get_schema(),
335
+ )
336
+
337
+ if self._dry:
338
+ self._sql = sql
339
+ return sql
340
+
341
+ return bool(self.new_connection().query(sql, ()))
342
+
343
+ def enable_foreign_key_constraints(self):
344
+ sql = self.platform().enable_foreign_key_constraints()
345
+
346
+ if self._dry:
347
+ self._sql = sql
348
+ return sql
349
+
350
+ return bool(self.new_connection().query(sql, ()))
351
+
352
+ def disable_foreign_key_constraints(self):
353
+ sql = self.platform().disable_foreign_key_constraints()
354
+
355
+ if self._dry:
356
+ self._sql = sql
357
+ return sql
358
+
359
+ return bool(self.new_connection().query(sql, ()))
@@ -0,0 +1,94 @@
1
+ from .Column import Column
2
+ from .Constraint import Constraint
3
+ from .ForeignKeyConstraint import ForeignKeyConstraint
4
+ from .Index import Index
5
+
6
+
7
+ class Table:
8
+ def __init__(self, table):
9
+ self.name = table
10
+ self.added_columns = {}
11
+ self.added_constraints = {}
12
+ self.added_indexes = {}
13
+ self.added_foreign_keys = {}
14
+ self.renamed_columns = {}
15
+ self.drop_indexes = {}
16
+ self.foreign_keys = {}
17
+ self.primary_key = None
18
+ self.comment = None
19
+
20
+ def add_column(
21
+ self,
22
+ name=None,
23
+ column_type=None,
24
+ length=None,
25
+ values=None,
26
+ nullable=False,
27
+ default=None,
28
+ signed=None,
29
+ default_is_raw=False,
30
+ primary=False,
31
+ column_python_type=str,
32
+ ):
33
+ column = Column(
34
+ name,
35
+ column_type,
36
+ length=length,
37
+ nullable=nullable,
38
+ values=values or [],
39
+ default=default,
40
+ signed=signed,
41
+ default_is_raw=default_is_raw,
42
+ column_python_type=column_python_type,
43
+ )
44
+ if primary:
45
+ column.set_as_primary()
46
+ self.added_columns.update({name: column})
47
+ return column
48
+
49
+ def add_constraint(self, name, constraint_type, columns=None):
50
+ self.added_constraints.update(
51
+ {name: Constraint(name, constraint_type, columns=columns or [])}
52
+ )
53
+
54
+ def add_foreign_key(
55
+ self, column, table=None, foreign_column=None, name=None
56
+ ):
57
+ foreign_key = ForeignKeyConstraint(
58
+ column,
59
+ table,
60
+ foreign_column,
61
+ name=name or f"{self.name}_{column}_foreign",
62
+ )
63
+ self.added_foreign_keys.update({column: foreign_key})
64
+
65
+ return foreign_key
66
+
67
+ def get_added_foreign_keys(self):
68
+ return self.added_foreign_keys
69
+
70
+ def get_constraint(self, name):
71
+ return self.added_constraints[name]
72
+
73
+ def get_added_constraints(self):
74
+ return self.added_constraints
75
+
76
+ def get_added_columns(self):
77
+ return self.added_columns
78
+
79
+ def get_renamed_columns(self):
80
+ return self.added_columns
81
+
82
+ def set_primary_key(self, columns):
83
+ self.primary_key = columns
84
+ return self
85
+
86
+ def add_index(self, column, name, index_type):
87
+ self.added_indexes.update({name: Index(column, name, index_type)})
88
+
89
+ def get_index(self, name):
90
+ return self.added_indexes[name]
91
+
92
+ def add_comment(self, comment):
93
+ self.comment = comment
94
+ return self