-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from collerek/add_index
Add multi columns non-unique index and sql_nullable setting. Important performance booster for dict().
- Loading branch information
Showing
23 changed files
with
751 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import databases | ||
import sqlalchemy | ||
|
||
import ormar | ||
|
||
database = databases.Database("sqlite:///db.sqlite") | ||
metadata = sqlalchemy.MetaData() | ||
|
||
|
||
class Course(ormar.Model): | ||
class Meta: | ||
database = database | ||
metadata = metadata | ||
# define your constraints in Meta class of the model | ||
# it's a list that can contain multiple constraints | ||
# hera a combination of name and column will have a compound index in the db | ||
constraints = [ormar.IndexColumns("name", "completed")] | ||
|
||
id: int = ormar.Integer(primary_key=True) | ||
name: str = ormar.String(max_length=100) | ||
completed: bool = ormar.Boolean(default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Any | ||
|
||
from sqlalchemy import Index, UniqueConstraint | ||
|
||
|
||
class UniqueColumns(UniqueConstraint): | ||
""" | ||
Subclass of sqlalchemy.UniqueConstraint. | ||
Used to avoid importing anything from sqlalchemy by user. | ||
""" | ||
|
||
|
||
class IndexColumns(Index): | ||
def __init__(self, *args: Any, name: str = None) -> None: | ||
if not name: | ||
name = "TEMPORARY_NAME" | ||
super().__init__(name, *args) | ||
|
||
""" | ||
Subclass of sqlalchemy.Index. | ||
Used to avoid importing anything from sqlalchemy by user. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.