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.
- masonite_framework_orm-3.0.1.dist-info/METADATA +87 -0
- masonite_framework_orm-3.0.1.dist-info/RECORD +116 -0
- masonite_framework_orm-3.0.1.dist-info/WHEEL +5 -0
- masonite_framework_orm-3.0.1.dist-info/entry_points.txt +3 -0
- masonite_framework_orm-3.0.1.dist-info/licenses/LICENSE +21 -0
- masonite_framework_orm-3.0.1.dist-info/top_level.txt +1 -0
- masoniteorm/__init__.py +1 -0
- masoniteorm/collection/Collection.py +605 -0
- masoniteorm/collection/__init__.py +1 -0
- masoniteorm/commands/CanOverrideConfig.py +16 -0
- masoniteorm/commands/CanOverrideOptionsDefault.py +22 -0
- masoniteorm/commands/Command.py +6 -0
- masoniteorm/commands/Entry.py +43 -0
- masoniteorm/commands/MakeMigrationCommand.py +57 -0
- masoniteorm/commands/MakeModelCommand.py +78 -0
- masoniteorm/commands/MakeModelDocstringCommand.py +37 -0
- masoniteorm/commands/MakeObserverCommand.py +54 -0
- masoniteorm/commands/MakeSeedCommand.py +54 -0
- masoniteorm/commands/MigrateCommand.py +46 -0
- masoniteorm/commands/MigrateFreshCommand.py +41 -0
- masoniteorm/commands/MigrateRefreshCommand.py +41 -0
- masoniteorm/commands/MigrateResetCommand.py +25 -0
- masoniteorm/commands/MigrateRollbackCommand.py +26 -0
- masoniteorm/commands/MigrateStatusCommand.py +51 -0
- masoniteorm/commands/SeedRunCommand.py +35 -0
- masoniteorm/commands/ShellCommand.py +205 -0
- masoniteorm/commands/__init__.py +18 -0
- masoniteorm/commands/stubs/create_migration.stub +20 -0
- masoniteorm/commands/stubs/create_seed.stub +9 -0
- masoniteorm/commands/stubs/model.stub +9 -0
- masoniteorm/commands/stubs/observer.stub +101 -0
- masoniteorm/commands/stubs/table_migration.stub +19 -0
- masoniteorm/config.py +123 -0
- masoniteorm/connections/BaseConnection.py +101 -0
- masoniteorm/connections/ConnectionFactory.py +59 -0
- masoniteorm/connections/ConnectionResolver.py +132 -0
- masoniteorm/connections/MSSQLConnection.py +176 -0
- masoniteorm/connections/MySQLConnection.py +232 -0
- masoniteorm/connections/PostgresConnection.py +225 -0
- masoniteorm/connections/SQLiteConnection.py +179 -0
- masoniteorm/connections/__init__.py +6 -0
- masoniteorm/exceptions.py +38 -0
- masoniteorm/expressions/__init__.py +1 -0
- masoniteorm/expressions/expressions.py +288 -0
- masoniteorm/factories/Factory.py +112 -0
- masoniteorm/factories/__init__.py +1 -0
- masoniteorm/helpers/__init__.py +0 -0
- masoniteorm/helpers/misc.py +22 -0
- masoniteorm/migrations/Migration.py +330 -0
- masoniteorm/migrations/__init__.py +1 -0
- masoniteorm/models/MigrationModel.py +9 -0
- masoniteorm/models/Model.py +1209 -0
- masoniteorm/models/Model.pyi +1366 -0
- masoniteorm/models/Pivot.py +5 -0
- masoniteorm/models/__init__.py +1 -0
- masoniteorm/observers/ObservesEvents.py +27 -0
- masoniteorm/observers/__init__.py +1 -0
- masoniteorm/pagination/BasePaginator.py +10 -0
- masoniteorm/pagination/LengthAwarePaginator.py +34 -0
- masoniteorm/pagination/SimplePaginator.py +28 -0
- masoniteorm/pagination/__init__.py +2 -0
- masoniteorm/providers/ORMProvider.py +39 -0
- masoniteorm/providers/__init__.py +1 -0
- masoniteorm/query/EagerRelation.py +42 -0
- masoniteorm/query/QueryBuilder.py +2486 -0
- masoniteorm/query/__init__.py +1 -0
- masoniteorm/query/grammars/BaseGrammar.py +1027 -0
- masoniteorm/query/grammars/MSSQLGrammar.py +194 -0
- masoniteorm/query/grammars/MySQLGrammar.py +238 -0
- masoniteorm/query/grammars/PostgresGrammar.py +213 -0
- masoniteorm/query/grammars/SQLiteGrammar.py +228 -0
- masoniteorm/query/grammars/__init__.py +4 -0
- masoniteorm/query/processors/MSSQLPostProcessor.py +58 -0
- masoniteorm/query/processors/MySQLPostProcessor.py +48 -0
- masoniteorm/query/processors/PostgresPostProcessor.py +49 -0
- masoniteorm/query/processors/SQLitePostProcessor.py +49 -0
- masoniteorm/query/processors/__init__.py +4 -0
- masoniteorm/relationships/BaseRelationship.py +161 -0
- masoniteorm/relationships/BelongsTo.py +124 -0
- masoniteorm/relationships/BelongsToMany.py +604 -0
- masoniteorm/relationships/HasMany.py +66 -0
- masoniteorm/relationships/HasManyThrough.py +269 -0
- masoniteorm/relationships/HasOne.py +111 -0
- masoniteorm/relationships/HasOneThrough.py +275 -0
- masoniteorm/relationships/MorphMany.py +152 -0
- masoniteorm/relationships/MorphOne.py +156 -0
- masoniteorm/relationships/MorphTo.py +111 -0
- masoniteorm/relationships/MorphToMany.py +108 -0
- masoniteorm/relationships/__init__.py +10 -0
- masoniteorm/schema/Blueprint.py +1161 -0
- masoniteorm/schema/Column.py +144 -0
- masoniteorm/schema/ColumnDiff.py +0 -0
- masoniteorm/schema/Constraint.py +5 -0
- masoniteorm/schema/ForeignKeyConstraint.py +28 -0
- masoniteorm/schema/Index.py +5 -0
- masoniteorm/schema/Schema.py +359 -0
- masoniteorm/schema/Table.py +94 -0
- masoniteorm/schema/TableDiff.py +86 -0
- masoniteorm/schema/__init__.py +3 -0
- masoniteorm/schema/platforms/MSSQLPlatform.py +367 -0
- masoniteorm/schema/platforms/MySQLPlatform.py +513 -0
- masoniteorm/schema/platforms/Platform.py +97 -0
- masoniteorm/schema/platforms/PostgresPlatform.py +551 -0
- masoniteorm/schema/platforms/SQLitePlatform.py +481 -0
- masoniteorm/schema/platforms/__init__.py +4 -0
- masoniteorm/scopes/BaseScope.py +6 -0
- masoniteorm/scopes/SoftDeleteScope.py +56 -0
- masoniteorm/scopes/SoftDeletesMixin.py +13 -0
- masoniteorm/scopes/TimeStampsMixin.py +12 -0
- masoniteorm/scopes/TimeStampsScope.py +47 -0
- masoniteorm/scopes/UUIDPrimaryKeyMixin.py +8 -0
- masoniteorm/scopes/UUIDPrimaryKeyScope.py +51 -0
- masoniteorm/scopes/__init__.py +8 -0
- masoniteorm/scopes/scope.py +15 -0
- masoniteorm/seeds/Seeder.py +42 -0
- masoniteorm/seeds/__init__.py +1 -0
|
@@ -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,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,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
|