Skip to main content

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"})

Metadata

Release files for koia 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for koia 0.0.12
File Size Uploaded Provenance Actions
koia-0.0.12.tar.gz 7.3 kB Without provenance Details for koia-0.0.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for koia 0.0.12
File Interpreter ABI Platform Actions
koia-0.0.12-py3-none-any.whl Python 3 none any Details for koia-0.0.12-py3-none-any.whl

Total release size: 16.7 kB

Release files / koia-0.0.12.tar.gz

Download URL koia-0.0.12.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c43dc0debe0001645c951769b09077806538add8df4b062723ffb5d97ce9cf37
BLAKE2b-256 checksum
How to use checksums
71d2f7929e6a5130e9b86ee265eabae7723d6b1c1944196bb9d55e1a77448690
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / koia-0.0.12-py3-none-any.whl

Download URL koia-0.0.12-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29e1aeb88461f6adfba7271d57183ee4f67bd4d9676ea6464eb8d63041c3e90b
BLAKE2b-256 checksum
How to use checksums
2ed4a0e272842fb54377d090e14893999299a7c74b8048e2da6a8e297d9d9508
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for koia 0.0.12

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page