This library helps you run MYSQL queries as fast as possible 🚄🔥!
Project description
cautious-pysql
CTpysql helps you to code mysql queries as fast as possible 🚄🔥
Usage
Installation
Use pip install ctpysql
to install the ctpysql and it's dependencies on your pc (or venv).
import module with:
from ctpysql import ctpysql
to use it in your project.
How it works?
You may import mysql.connector to work with ctpysql, just use:
from mysql.connector import (connection, Error)
and make a connection like this:
cnx = connection.MySQLConnection(user='root', password='password', host='127.0.0.1', database='db')
then make an object from ctpysql class using this connection:
obj = ctpysql(cnx)
after these steps you are able to use this library correctly, for example, insert query using dictionary values:
obj.insert('users', {'username': 'user1', 'password': 'password1'})
Supported queries
Supported queries at this version (they will be more soon):
Insert
Last rowid inserted return
insert('table', {dictionary values})
Truncate:
truncate('table')
Select
Selected row(s) return
fetch('table', 'case [all or one]', 'type [dic or None]', **data)
Example:
fetch('users', 'one', None, id=3)
Select all
Selected row(s) return
fetchall('table', 'type [dic or None]')
Example 1:
fetchall('products', None)
Example 2:
fetchall('products', 'dic')
Update
Affected rows count return
update('table', 'condition column name', 'condition column value', **data)
Example:
update('users', 'username', usernameVar, password=123, email=a@a.com)
Delete
Deleted rows count return
delete('table', 'condition column name', 'condition value')
Drop
"Success" or error return
drop('case', 'name')
Example:
drop('table', 'product')
Example2:
drop('view', '[mysql queries]')
Order
Fetched items return
order('table', **data(column1="order like ASC", column2="order like DESC"))
Example:
order('products', name="ASC", id="DESC")
Create table
"Success" or error return
create_table('table name', **data)
Example:
create_table('users', id="INT AUTO_INCREMENT PRIMARY KEY", name="VARCHAR(255)")
Between
Fetched rows return
between('table name', 'type [dic or None]', 'condition column', 'first parameter', 'second parameter')
Example:
between('products', None, 'id', 1, 4)
Don't forget!
Don't forget this is a class and you should call this functions from an object of class. A full example here:
from mysql.connector import (connection, Error)
from ctpysql import ctpysql
connection = connection.MySQLConnection(user='root', password='password', host='127.0.0.1', database='testdb')
object = ctpysql(cnx)
object.insert('products', {'name': 'Laptop', 'brand': 'Asus'})
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
Built Distribution
File details
Details for the file ctpysql-1.4.5.tar.gz
.
File metadata
- Download URL: ctpysql-1.4.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4098003e1eec92699e65915fa67a62bf54703324ac2e34e4885dbfeac66c61bc |
|
MD5 | 90ed642654e1b62cb4238c94db701faf |
|
BLAKE2b-256 | 065ce3e77db8b249e86646c0ef31df0abfc0c02886d18c30eec0be29e314233e |
File details
Details for the file ctpysql-1.4.5-py3-none-any.whl
.
File metadata
- Download URL: ctpysql-1.4.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf823b3c2f011a0db18038a728da20307dcbd07e42a6a35b2d23938e16b03b11 |
|
MD5 | 631762fff17791da0c38a0906fa06557 |
|
BLAKE2b-256 | a27ca047cdacf947cd9feb63fdece977c4245fcc31c3bba0ec3e540625a7f635 |