Sql query builder interface
Project description
Koia
Installation
Via github
git clone https://github.com/Kel0/koia.git
pip install invoke
inv install
Via pip
pip install koia
Code example
Get data
from typing import Dict
from koia.connector import Database
from koia.FetchBuilder import FetchBuilder
database: Database = Database(config={
"host": "host",
"user": "root",
"password": "1234",
"database": "base"
}, autocommit=False)
fetch_builder: FetchBuilder = FetchBuilder(database=database)
data: list = (
fetch_builder.table("myTable")
.where("column", "=", value)
.orWhere("column", "LIKE", f"%{value}%")
.whereNotNull("column")
.whereIn("column", [value1, value2])
.orderBy("column", "DESC")
.take(2)
.get()
)
Some details
(
fetch_builder.table("myTable")
.where("column", "=", value)
.orWhere("column", "LIKE", f"%{value}%")
.whereNotNull("column")
.whereIn("column", [value1, value2])
.orderBy("column", "DESC")
.take(2)
.get()
) -> SELECT * FROM myTable
WHERE `column` = value
OR `column` LIKE '%value%'
AND `column` IS NOT NULL
AND `column` IN (value1, value2)
ORDER BY `column` DESC
LIMIT 2
Inner join
from typing import Dict
from koia.connector import Database
from koia.FetchBuilder import FetchBuilder
database: Database = Database(config={
"host": "host",
"user": "root",
"password": "1234",
"database": "base"
}, autocommit=False)
fetch_builder: FetchBuilder = FetchBuilder(database=database)
data: list = (
fetch_builder.table("myTable")
.innerJoin(table="myTable2", specification={
"myTable.id": "myTable2.id", "myTable.col": "myTable2.col"
})
.innerJoin(table="myTable3", specification={
"myTable.id": "myTable3.id", "myTable.col": "myTable3.col"
})
.whereNotNull("column")
.get()
)
Some details
data = (
fetch_builder.table("myTable")
.innerJoin(table="myTable2", specification={
"myTable2.id": "myTable.id", "myTable2.col": "myTable.col"
})
.innerJoin(table="myTable3", specification={
"myTable3.id": "myTable.id", "myTable3.col": "myTable.col"
})
.whereNotNull("column")
.get()
) -> SELECT * FROM myTable
INNER JOIN myTable2 ON (myTable2.id = myTable.id) and (myTable2.col = myTable.col)
INNER JOIN myTable2 ON (myTable3.id = myTable.id) and (myTable3.col = myTable.col)
WHERE `column` IS NOT NULL
Insert data
from typing import Dict
from koia.connector import Database
from koia.FetchBuilder import FetchBuilder
database: Database = Database(config={
"host": "host",
"user": "root",
"password": "1234",
"database": "base"
}, autocommit=False)
fetch_builder: FetchBuilder = FetchBuilder(database=database)
(
fetch_builder.table("myTable")
.insert({
"column": "value"
})
)
Some details
(
fetch_builder.table("myTable")
.insert({
"column": "value"
})
) -> INSERT INTO myTable
(`column`) VALUES (value)
Update data
from typing import Dict
from koia.connector import Database
from koia.FetchBuilder import FetchBuilder
database: Database = Database(config={
"host": "host",
"user": "root",
"password": "1234",
"database": "base"
}, autocommit=False)
fetch_builder: FetchBuilder = FetchBuilder(database=database)
(
fetch_builder.table("myTable")
.update({
"column": "value"
})
.where("column", "LIKE", "%{value}%")
)
Some details
(
fetch_builder.table("myTable")
.update({
"column": "value"
})
.where("column", "LIKE", "%{value}%")
) -> UPDATE myTable SET `column` = value
WHERE `column` LIKE '%value%'
Models
from dataclasses import dataclass
from koia.database.connector import Database
from koia.models.model import BaseModel
from koia.types.model_types import String, Integer, Float, Text, Column
@dataclass
class CurrentDatabase:
database: Database = Database(
config={
"host": "host",
"user": "root",
"password": "1234",
"database": "base"
},
autocommit=False
)
class City_code(BaseModel):
__tablename__ = "city_codes"
database: Database = CurrentDatabase.database
id = Column(Integer, pk=True, autoincrement=True)
city_code = Column(String(max_length=225))
a = City_code().get(filter=["column = value"], orderBy={"col": "DESC"})
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
koia-0.0.12.tar.gz
(7.3 kB
view details)
Built Distribution
koia-0.0.12-py3-none-any.whl
(9.4 kB
view details)
File details
Details for the file koia-0.0.12.tar.gz
.
File metadata
- Download URL: koia-0.0.12.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c43dc0debe0001645c951769b09077806538add8df4b062723ffb5d97ce9cf37 |
|
MD5 | 7ede1f84d960edb8236e3d7eef28c224 |
|
BLAKE2b-256 | 71d2f7929e6a5130e9b86ee265eabae7723d6b1c1944196bb9d55e1a77448690 |
File details
Details for the file koia-0.0.12-py3-none-any.whl
.
File metadata
- Download URL: koia-0.0.12-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29e1aeb88461f6adfba7271d57183ee4f67bd4d9676ea6464eb8d63041c3e90b |
|
MD5 | 303368a31e851a17bc731cc46c871c08 |
|
BLAKE2b-256 | 2ed4a0e272842fb54377d090e14893999299a7c74b8048e2da6a8e297d9d9508 |