Simple Module Using Raw SQL To Get Insert Update Database
Project description
Simple Module For Database
This is a simple Python module that provides functions to perform basic insert, update, and delete actions on a database.
Installation
To use this module, you need to have Python installed on your system. You can install the module using pip:
pip install raw-database
Usage
Import the module into your Python script:
from raw_database import Insert, Update, QuerySet
Insert Action
Insert(connection, is_commit=False).into(table).values(**values).returning(return_key).fetchone()
- connection: Connection to database
- is_commit: Determine whether to commit this data
- table: The name of the table where the data will be inserted.
- values: A dictionary containing the data to be inserted, with column names as keys and corresponding values.
- return_key: A key will be return if insert is success
Example usage:
Insert(connection_, is_commit=False).into("accounts").values(user_id=6, username="Tom B", email="test email").returning("user_id").fetchone()
Update Action
Update(connection, is_commit=False)(table).set(**values).where(**conditions).returning(return_key).fetchone()
- connection: Connection to database
- is_commit: Determine whether to commit this data
- table: The name of the table where the data will be inserted.
- values: A dictionary containing the data to be inserted, with column names as keys and corresponding values.
- conditions: A dictionary containing conditions to update
- return_key: A key will be return if insert is success
Example usage:
Update(connection_, is_commit=False)(table="accounts").set(email="test email update", username="test username update").where(user_id=1).returning("user_id").fetchone()
Get Action
QuerySet(connection).select(*fields).from_(table).where(**condition).fetchone()
- connection: Connection to database
- fields: A list containing the selected from table
- table: The name of the table where the data will be inserted.
- conditions: A dictionary containing conditions to update
Example usage:
QuerySet(connection_).select("user_id", "username").from_("accounts").where(user_id=1).fetchone()
QuerySet(connection_).select().from_("accounts").fetchall()
QuerySet(connection_).select().from_("accounts").limit(2).fetchall()
QuerySet(connection_).select().from_("accounts").order_by("user_id DESC").fetchall()
QuerySet(connection_).select("user_id").from_("accounts").where(user_id__in=(1, 2, 3), username='Tom B. Erichsen').fetchall()
QuerySet(connection_).select("user_id").from_("accounts").where(user_id__in=(1, 2, 3)).fetchall()
QuerySet(connection_).select("password", "COUNT(*) AS same_password").from_("accounts").where(user_id__in=(1, 2, 3, 4)).group_by("password").fetchall()
Contributing
Contributions are welcome! If you'd like to contribute to this module, please follow these steps:
- Fork the repository.
- Create a new branch for your feature/bug fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
raw_databases-0.0.1.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raw_databases-0.0.1.tar.gz.
File metadata
- Download URL: raw_databases-0.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fb63b23f5fa0bf01d7c130a0ae20b261a95319559f45b9488a5cd637895f857
|
|
| MD5 |
0216dd355ca51d90541e8be3767c587d
|
|
| BLAKE2b-256 |
4a3e983826d691c1230a9270de6d3f648cdcecb6302d1ab7892fb2575b5aa130
|
File details
Details for the file raw_databases-0.0.1-py3-none-any.whl.
File metadata
- Download URL: raw_databases-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c1c3221d62cac0e0c965fb48b09bc9027d6732744b154277304fdbe1b713fb0
|
|
| MD5 |
0e50b5d824adcb24f56e1b1b2628cf40
|
|
| BLAKE2b-256 |
6f60441baa7d3b68181a658dc4520db29c147a86ffba90381529f614331794f7
|