SimpleSql
An sql module that requires no knowledge of sql syntax.
Installation
The simple sql module can be installed with pip
pip install pyssql
Demo
import pyssql
class User(
pyssql.Class
): # To create a class that can be stored in the database it must inherit simplesql.Class
user_count: int = 0 # Will not be restored when loading from database
# Sql types (these will be stored and loaded when storing to or loading from a database)
id: pyssql.Types.Integer(key=pyssql.Key.PRIMARY)
username: pyssql.Types.String(max_length=50, not_null=True)
def __init__(self, username: str) -> None:
self.id = User.user_count
self.username = username
User.user_count += 1
def on_load(
self,
) -> None: # Called when loading from database, this method is optional
print("Loading user", self.username, "with id", self.id)
def show(self) -> None:
print("ID:", self.id)
print("Username:", self.username)
# We'll create a database located in memory (by setting the path to ":memory:"), if you want to save it in a file and edit it later use a file path instead
database = pyssql.Database(":memory:", classes=[User])
# Populating the database
database.insert(User("John"))
database.insert(User("Mike"))
database.insert(User("Steve"))
database.insert(User("Jane"))
database.insert(User("Lisa"))
# Using the & operator is not recommended as it is very error prone
# users = database.select(User).where((User.id < 4) & (User.id > 2)).all()
# Instead chain the where(condition) method
users = (
database.select(User).where(User.id < 4).where(User.id > 2).all()
) # Same as User.id == 3
for user in users:
user.show()
john = database.select(User).where(User.username == "John").first()
john.show()
# When loading objects from the database, all their values will be converted to python types
print(type(john.id)) # <class 'int'>
Downloads
Metadata
Release files for pyssql 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyssql-1.0.1-py3.9.egg | Legacy Egg format | - | - | Details for pyssql-1.0.1-py3.9.egg |
Release files / pyssql-1.0.1-py3.9.egg
| Download URL | pyssql-1.0.1-py3.9.egg |
|---|---|
| Size | 11.6 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
1a76dda6f3552af44785a2549ec8851a250e0ad5c7d1d2cf645c5406de57de1b
|
|
BLAKE2b-256 checksum How to use checksums |
ad72c028203fc7fddfd4f877717835fe53b9d0e0e75af9bc9fdbd21539c4efe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for pyssql 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.