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,5 @@
1
+ from .Model import Model
2
+
3
+
4
+ class Pivot(Model):
5
+ __primary_key__ = "id"
@@ -0,0 +1 @@
1
+ from .Model import Model
@@ -0,0 +1,27 @@
1
+ class ObservesEvents:
2
+ def observe_events(self, model, event):
3
+ if model.__has_events__ == True:
4
+ for observer in model.__observers__.get(model.__class__, []):
5
+ try:
6
+ getattr(observer, event)(model)
7
+ except AttributeError:
8
+ pass
9
+
10
+ @classmethod
11
+ def observe(cls, observer):
12
+ if cls in cls.__observers__:
13
+ cls.__observers__[cls].append(observer)
14
+ else:
15
+ cls.__observers__.update({cls: [observer]})
16
+
17
+ @classmethod
18
+ def without_events(cls):
19
+ """Sets __has_events__ attribute on model to false."""
20
+ cls.__has_events__ = False
21
+ return cls
22
+
23
+ @classmethod
24
+ def with_events(cls):
25
+ """Sets __has_events__ attribute on model to True."""
26
+ cls.__has_events__ = True
27
+ return cls
@@ -0,0 +1 @@
1
+ from .ObservesEvents import ObservesEvents
@@ -0,0 +1,10 @@
1
+ import json
2
+
3
+
4
+ class BasePaginator:
5
+ def __iter__(self):
6
+ for result in self.result:
7
+ yield result
8
+
9
+ def to_json(self):
10
+ return json.dumps(self.serialize())
@@ -0,0 +1,34 @@
1
+ import math
2
+
3
+ from .BasePaginator import BasePaginator
4
+
5
+
6
+ class LengthAwarePaginator(BasePaginator):
7
+ def __init__(self, result, per_page, current_page, total, url=None):
8
+ self.result = result
9
+ self.current_page = current_page
10
+ self.per_page = per_page
11
+ self.count = len(self.result)
12
+ self.last_page = int(math.ceil(total / per_page))
13
+ self.next_page = (
14
+ (int(self.current_page) + 1) if self.has_more_pages() else None
15
+ )
16
+ self.previous_page = (int(self.current_page) - 1) or None
17
+ self.total = total
18
+ self.url = url
19
+
20
+ def serialize(self, *args, **kwargs):
21
+ return {
22
+ "data": self.result.serialize(*args, **kwargs),
23
+ "meta": {
24
+ "total": self.total,
25
+ "next_page": self.next_page,
26
+ "count": self.count,
27
+ "previous_page": self.previous_page,
28
+ "last_page": self.last_page,
29
+ "current_page": self.current_page,
30
+ },
31
+ }
32
+
33
+ def has_more_pages(self):
34
+ return self.current_page < self.last_page
@@ -0,0 +1,28 @@
1
+ from .BasePaginator import BasePaginator
2
+
3
+
4
+ class SimplePaginator(BasePaginator):
5
+ def __init__(self, result, per_page, current_page, url=None):
6
+ self.result = result
7
+ self.current_page = current_page
8
+ self.per_page = per_page
9
+ self.count = len(self.result)
10
+ self.next_page = (
11
+ (int(self.current_page) + 1) if self.has_more_pages() else None
12
+ )
13
+ self.previous_page = (int(self.current_page) - 1) or None
14
+ self.url = url
15
+
16
+ def serialize(self, *args, **kwargs):
17
+ return {
18
+ "data": self.result.serialize(*args, **kwargs),
19
+ "meta": {
20
+ "next_page": self.next_page,
21
+ "count": self.count,
22
+ "previous_page": self.previous_page,
23
+ "current_page": self.current_page,
24
+ },
25
+ }
26
+
27
+ def has_more_pages(self):
28
+ return len(self.result) > self.per_page
@@ -0,0 +1,2 @@
1
+ from .LengthAwarePaginator import LengthAwarePaginator
2
+ from .SimplePaginator import SimplePaginator
@@ -0,0 +1,39 @@
1
+ from masonite.providers import Provider
2
+
3
+ from masoniteorm.commands import (
4
+ MakeMigrationCommand,
5
+ MakeModelCommand,
6
+ MakeObserverCommand,
7
+ MakeSeedCommand,
8
+ MigrateCommand,
9
+ MigrateRefreshCommand,
10
+ MigrateResetCommand,
11
+ MigrateRollbackCommand,
12
+ MigrateStatusCommand,
13
+ SeedRunCommand,
14
+ )
15
+
16
+
17
+ class ORMProvider(Provider):
18
+ """Masonite ORM database provider to be used inside
19
+ Masonite based projects."""
20
+
21
+ def __init__(self, application):
22
+ self.application = application
23
+
24
+ def register(self):
25
+ self.application.make("commands").add(
26
+ MakeMigrationCommand(),
27
+ MakeSeedCommand(),
28
+ MakeObserverCommand(),
29
+ MigrateCommand(),
30
+ MigrateResetCommand(),
31
+ MakeModelCommand(),
32
+ MigrateStatusCommand(),
33
+ MigrateRefreshCommand(),
34
+ MigrateRollbackCommand(),
35
+ SeedRunCommand(),
36
+ ),
37
+
38
+ def boot(self):
39
+ pass
@@ -0,0 +1 @@
1
+ from .ORMProvider import ORMProvider
@@ -0,0 +1,42 @@
1
+ class EagerRelations:
2
+ def __init__(self, relation=None):
3
+ self.eagers = []
4
+ self.nested_eagers = {}
5
+ self.callback_eagers = {}
6
+ self.is_nested = False
7
+ self.relation = relation
8
+
9
+ def register(self, *relations, callback=None):
10
+ for relation in relations:
11
+ if isinstance(relation, str) and "." not in relation:
12
+ self.eagers += [relation]
13
+ elif isinstance(relation, str) and "." in relation:
14
+ self.is_nested = True
15
+ relation_key = relation.split(".")[0]
16
+ if relation_key not in self.nested_eagers:
17
+ self.nested_eagers = {
18
+ relation_key: relation.split(".")[1:]
19
+ }
20
+ else:
21
+ self.nested_eagers[relation_key] += relation.split(".")[1:]
22
+ elif isinstance(relation, (tuple, list)):
23
+ for eagers in relations:
24
+ for eager in eagers:
25
+ self.register(eager)
26
+ elif isinstance(relation, dict):
27
+ self.callback_eagers.update(relation)
28
+
29
+ return self
30
+
31
+ def get_eagers(self):
32
+ eagers = []
33
+ if self.eagers:
34
+ eagers.append(self.eagers)
35
+
36
+ if self.nested_eagers:
37
+ eagers.append(self.nested_eagers)
38
+
39
+ if self.callback_eagers:
40
+ eagers.append(self.callback_eagers)
41
+
42
+ return eagers