Name | sqlite3-orm JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | Django style ORM for sqlite3 |
upload_time | 2024-04-19 10:31:47 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | Copyright © 2024 Thraize Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
database
sqlite
orm
|
VCS |
|
bugtrack_url |
|
requirements |
bottle
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Sqlite ORM
Sqlite orm modeled after django orm
# Quick Demo
```python
from sqlite import SqliteDatabase
db = SqliteDatabase(":memory:")
# Catch all errors
@db.on("error")
def _(err):
raise err
class Session(db.Model):
sid: int # Type Number
data: str # Type Text
class User(db.Model):
name: str
age: int
password: bytes # Type blob
# Instance method
def verify_password(self, password):
return self.password == password
class Note(db.Model):
name: str # Not null field
body: str = '' # Default field
user: User # Foreign Key assignment
users: list[User] # Many to one keys
# Get or create entry
bob = User(name="Bob", age=7, password=b"MyAwesomePassword")
# Check if entry exists
print(bob.id != None)
# Update entry
bob.age = (bob.age + 1)
# Save entry
bob.save()
# Call nstance method
print(bob.verify_password(b""))
# Get multiple entries
notes = Note.objects.get(user=bob)
```
## Authentication and Authorization model demo
```python
from sqlite import SqliteDatabase
from sqlite.columns import *
from sqlite.files import FileSystemStorage
database = SqliteDatabase("./db.sqlite")
@database.on('error')
def error(e):
raise e
# For easier access to files and folders
# Call 'create' to create directory if not exists
store = FileSystemStorage(directory="./media").create()
# Go to subdirectory
# Sames api as FileSystemStorage object
uploads = store["uploads"].create()
class Role(database.Model):
role: str = SelectColumn(options=["admin", "editor", "user", "superuser"])
level: int = IntegerColumn(null=False, min=1, max=100)
def __str__(self):
return f"[{self.id}] role -> {self.role}: level -> {self.level}"
class Meta:
table_name = "auth_role"
class User(database.Model):
username: str
email_addr: str = EmailColumn(
label="Email Address",
helper_text="User's email address: '@' must be present",
unique=True
)
desc: str = Column(
label="Description",
helper_text="Description of the user"
)
creation_date: datetime = DateTimeColumn(null=False)
image: str = ImageColumn(
extensions=["jpg", "png"],
store=uploads, default="default.png",
label="Image"
)
last_login: datetime = DateTimeColumn()
hash: bytes = BytesColumn(null=False)
is_active: bool = BooleanColumn()
@property
def tag(self):
return f"@{self.username}".lower()
def __str__(self):
return f"[{self.id}] username -> {self.username}"
class Meta:
table_name = "auth_users"
class PendingReg(database.Model):
code: str
email_addr: str = EmailColumn(label="Email Address")
desc: str = Column(editor="full", label="Description")
hash: bytes = BytesColumn(null=False)
username: str = Column(null=False)
creation_date: datetime = DateTimeColumn(null=False, label="Date Created")
class Meta:
table_name = "auth_pending_registrations"
class Token(database.Model):
tokenid: str
last_used: datetime = DateTimeColumn(null=True)
is_expired = BooleanColumn(default=False)
usage_amount: int = IntegerColumn(default=0)
usage_limit: int = IntegerColumn()
user = ForeignKeyColumn(User)
value: str = Column(null=False)
creation_date: datetime = DateTimeColumn(null=False, label="Created")
expiry_date: datetime = DateTimeColumn(null=True)
@property
def owner(self):
return User.objects.get(id=self.user_id)
class Meta:
table_name = "auth_tokens"
class AuthAttempts(database.Model):
ip_address: str = Column(null=False)
user_agent: str = Column(null=False)
token: str = Column(null=False)
created_at = DateTimeColumn()
class Meta:
table_name = "auth_activation_attempts"
class Permissions(database.Model):
name: str = Column(null=False)
description: str = Column(null=False)
class Meta:
table_name = 'auth_permissions'
class UsersPermissions(database.Model):
user = ForeignKeyColumn(User)
permission = ForeignKeyColumn(Permissions)
class Meta:
table_name = 'auth_users_permissions'
class Groups(database.Model):
name: str = Column(null=False)
description: str = Column(null=False)
class Meta:
table_name = 'auth_groups'
class GroupsUsers(database.Model):
user: int = ForeignKeyColumn(User)
group: int = ForeignKeyColumn(Groups, name="user_group")
class Meta:
table_name = 'auth_groups_users'
class GroupsPermissions(database.Model):
group = ForeignKeyColumn(Groups, name="user_group")
permission = ForeignKeyColumn(Permissions)
class Meta:
table_name = 'auth_groups_permissions'
```
Raw data
{
"_id": null,
"home_page": null,
"name": "sqlite3-orm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "database, sqlite, orm",
"author": null,
"author_email": "Thraize <gamerxville@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/34/04/a3aeb21f5b6d93f06d4a185a72121507c2e2790002b7ef6449b9fce2f2de/sqlite3_orm-1.0.0.tar.gz",
"platform": null,
"description": "# Sqlite ORM\n\nSqlite orm modeled after django orm\n\n# Quick Demo\n```python\nfrom sqlite import SqliteDatabase\n\ndb = SqliteDatabase(\":memory:\")\n\n# Catch all errors\n@db.on(\"error\")\ndef _(err):\n raise err\n\n\nclass Session(db.Model):\n sid: int # Type Number\n data: str # Type Text\n\n\nclass User(db.Model):\n name: str\n age: int \n password: bytes # Type blob\n\n # Instance method\n def verify_password(self, password):\n return self.password == password\n\n\nclass Note(db.Model):\n name: str # Not null field\n body: str = '' # Default field\n user: User # Foreign Key assignment\n users: list[User] # Many to one keys\n\n# Get or create entry\nbob = User(name=\"Bob\", age=7, password=b\"MyAwesomePassword\")\n\n# Check if entry exists\nprint(bob.id != None)\n\n# Update entry\nbob.age = (bob.age + 1)\n\n# Save entry\nbob.save()\n\n# Call nstance method\nprint(bob.verify_password(b\"\"))\n\n# Get multiple entries\nnotes = Note.objects.get(user=bob)\n\n```\n\n## Authentication and Authorization model demo\n```python\nfrom sqlite import SqliteDatabase\nfrom sqlite.columns import *\nfrom sqlite.files import FileSystemStorage\n\ndatabase = SqliteDatabase(\"./db.sqlite\")\n\n@database.on('error')\ndef error(e):\n raise e\n\n# For easier access to files and folders\n# Call 'create' to create directory if not exists\nstore = FileSystemStorage(directory=\"./media\").create()\n\n# Go to subdirectory\n# Sames api as FileSystemStorage object\nuploads = store[\"uploads\"].create()\n\nclass Role(database.Model):\n role: str = SelectColumn(options=[\"admin\", \"editor\", \"user\", \"superuser\"])\n level: int = IntegerColumn(null=False, min=1, max=100)\n\n def __str__(self):\n return f\"[{self.id}] role -> {self.role}: level -> {self.level}\"\n\n class Meta:\n table_name = \"auth_role\"\n\nclass User(database.Model):\n username: str\n email_addr: str = EmailColumn(\n label=\"Email Address\",\n helper_text=\"User's email address: '@' must be present\",\n unique=True\n )\n desc: str = Column(\n label=\"Description\",\n helper_text=\"Description of the user\"\n )\n creation_date: datetime = DateTimeColumn(null=False)\n image: str = ImageColumn(\n extensions=[\"jpg\", \"png\"],\n store=uploads, default=\"default.png\",\n label=\"Image\"\n )\n last_login: datetime = DateTimeColumn()\n hash: bytes = BytesColumn(null=False)\n is_active: bool = BooleanColumn()\n\n @property\n def tag(self):\n return f\"@{self.username}\".lower()\n \n def __str__(self):\n return f\"[{self.id}] username -> {self.username}\"\n \n class Meta:\n table_name = \"auth_users\"\n\nclass PendingReg(database.Model):\n code: str\n email_addr: str = EmailColumn(label=\"Email Address\")\n desc: str = Column(editor=\"full\", label=\"Description\")\n hash: bytes = BytesColumn(null=False)\n username: str = Column(null=False)\n creation_date: datetime = DateTimeColumn(null=False, label=\"Date Created\")\n \n class Meta:\n table_name = \"auth_pending_registrations\"\n\nclass Token(database.Model):\n tokenid: str\n last_used: datetime = DateTimeColumn(null=True)\n is_expired = BooleanColumn(default=False)\n usage_amount: int = IntegerColumn(default=0)\n usage_limit: int = IntegerColumn()\n user = ForeignKeyColumn(User)\n value: str = Column(null=False)\n creation_date: datetime = DateTimeColumn(null=False, label=\"Created\")\n expiry_date: datetime = DateTimeColumn(null=True)\n \n @property\n def owner(self):\n return User.objects.get(id=self.user_id)\n \n class Meta:\n table_name = \"auth_tokens\"\n\nclass AuthAttempts(database.Model):\n ip_address: str = Column(null=False)\n user_agent: str = Column(null=False)\n token: str = Column(null=False)\n created_at = DateTimeColumn()\n\n class Meta:\n table_name = \"auth_activation_attempts\"\n\nclass Permissions(database.Model):\n name: str = Column(null=False)\n description: str = Column(null=False)\n\n class Meta:\n table_name = 'auth_permissions'\n\nclass UsersPermissions(database.Model):\n user = ForeignKeyColumn(User)\n permission = ForeignKeyColumn(Permissions)\n\n class Meta:\n table_name = 'auth_users_permissions'\n\nclass Groups(database.Model):\n name: str = Column(null=False)\n description: str = Column(null=False)\n\n class Meta:\n table_name = 'auth_groups'\n\nclass GroupsUsers(database.Model):\n user: int = ForeignKeyColumn(User)\n group: int = ForeignKeyColumn(Groups, name=\"user_group\")\n\n class Meta:\n table_name = 'auth_groups_users'\n\nclass GroupsPermissions(database.Model):\n group = ForeignKeyColumn(Groups, name=\"user_group\")\n permission = ForeignKeyColumn(Permissions)\n\n class Meta:\n table_name = 'auth_groups_permissions'\n```\n",
"bugtrack_url": null,
"license": "Copyright \u00a9 2024 Thraize Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Django style ORM for sqlite3",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/7HR4IZ3/Sqlite-ORM"
},
"split_keywords": [
"database",
" sqlite",
" orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2476c11d52b037edb26032943bf5c70189d0801956d391c4ffb64c5569a3fbc0",
"md5": "ca28ef89b0012c4f704c8181697d9649",
"sha256": "e0b856368dd03ac9ec5274b0e946b5daee6702aad9059aed25b9022c9a658f86"
},
"downloads": -1,
"filename": "sqlite3_orm-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ca28ef89b0012c4f704c8181697d9649",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 25298,
"upload_time": "2024-04-19T10:31:45",
"upload_time_iso_8601": "2024-04-19T10:31:45.422869Z",
"url": "https://files.pythonhosted.org/packages/24/76/c11d52b037edb26032943bf5c70189d0801956d391c4ffb64c5569a3fbc0/sqlite3_orm-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3404a3aeb21f5b6d93f06d4a185a72121507c2e2790002b7ef6449b9fce2f2de",
"md5": "b1755cd68c9dd793c3da8d8198eb2662",
"sha256": "5fcf29677ebed41a5a6d0f61f8e2a77941ab6463097cfe99aa7e77e2d7831545"
},
"downloads": -1,
"filename": "sqlite3_orm-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "b1755cd68c9dd793c3da8d8198eb2662",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 22938,
"upload_time": "2024-04-19T10:31:47",
"upload_time_iso_8601": "2024-04-19T10:31:47.962554Z",
"url": "https://files.pythonhosted.org/packages/34/04/a3aeb21f5b6d93f06d4a185a72121507c2e2790002b7ef6449b9fce2f2de/sqlite3_orm-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-19 10:31:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "7HR4IZ3",
"github_project": "Sqlite-ORM",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "bottle",
"specs": []
}
],
"lcname": "sqlite3-orm"
}