Giter Club home page Giter Club logo

pysqlx-engine's Introduction

PySQLXEngine

PySQLXEngine Logo

PySQLXEngine, a fast and minimalist SQL engine

CI Coverage Package version Supported Python versions Downloads


Documentation: https://carlos-rian.github.io/pysqlx-engine/

Source Code: https://github.com/carlos-rian/pysqlx-engine


PySQLXEngine supports the option of sending Raw SQL to your database.

The PySQLXEngine is a minimalist SQL Engine.

The PySQLXEngine was created and thought to be minimalistic, but very efficient. The core is write in Rust, making communication between Databases and Python more efficient.

All SQL executed using PySQLXEngine is atomic; only one instruction is executed at a time. Only the first one will be completed if you send an Insert and a select. This is one of the ways to handle SQL ingestion. As of version 0.2.0, PySQLXEngine supports transactions, where you can control BEGIN, COMMIT, ROLLBACK , ISOLATION LEVEL, etc. as you wish.

NOTE: Minimalism is not the lack of something, but having exactly what you need. PySQLXEngine aims to expose an easy interface for you to communicate with the database in a simple, intuitive way and with good help through documentation, autocompletion, typing, and good practices.


Database Support:

OS Support:

Installation

PIP

$ pip install pysqlx-engine

Poetry

$ poetry add pysqlx-engine

Async Example

Create a main.py file and add the code examples below.

from pysqlx_engine import PySQLXEngine

async def main():
    db = PySQLXEngine(uri="sqlite:./db.db")
    await db.connect()

    await db.execute(sql="""
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY, 
            name TEXT, 
            age INT
        )
    """)
    await db.execute(sql="INSERT INTO users (name, age) VALUES ('Rian', '28')")
    await db.execute(sql="INSERT INTO users (name, age) VALUES ('Carlos', '29')")

    rows = await db.query(sql="SELECT * FROM users")

    print(rows)

import asyncio
asyncio.run(main())

Sync Example

Create a main.py file and add the code examples below.

from pysqlx_engine import PySQLXEngineSync

def main():
    db = PySQLXEngineSync(uri="sqlite:./db.db")
    db.connect()

    db.execute(sql="""
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY, 
            name TEXT, 
            age INT
        )
    """)
    db.execute(sql="INSERT INTO users (name, age) VALUES ('Rian', '28')")
    db.execute(sql="INSERT INTO users (name, age) VALUES ('Carlos', '29')")

    rows = db.query(sql="SELECT * FROM users")

    print(rows)

# running the code
main()

Running the code using the terminal

$ python3 main.py

Output

[
    BaseRow(id=1, name='Rian', age=28),  
    BaseRow(id=2, name='Carlos', age=29)
]

pysqlx-engine's People

Contributors

carlos-rian avatar carlos-rian-quartile avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pysqlx-engine's Issues

PostgreSQL - Could not convert value to IpAddr

Description

I ran a query_raw where the PostgreSQL column is of type CIDR or MacAddr but I got this error.

This message is in the src/ast/values.rs file, line 788.

Value in column: 192.168.100.128/25 and 08:00:2b:01:02:03

Error

CIDR
Error querying the database: error deserializing column 24: cannot convert between the Rust type core::option::Option<std::net::ip::IpAddr> and the Postgres type cidr

MacAddr has the same problem
Column type 'macaddr' could not be deserialized from the database.

issue core link: prisma/quaint#416

[engine] - performance tests

Create benchmark tests using any driver vs pysqlx-engine

PostgreSQL.

  • sync - psycopg2
  • async - asyncpg

MySQL

  • sync - mysql-connector-python
  • async - aiomysql

SQLite

  • sync - sqlite3
  • async - aiosqlite

MS SQL Server

  • sync - pyodbc

Test Topics

  • pysqlx-engine VS psycopg2
  • pysqlx-engine VS asyncpg
  • pysqlx-engine VS mysql-connector-python
  • pysqlx-engine VS aiomysql
  • pysqlx-engine VS sqlite3
  • pysqlx-engine VS aiosqlite
  • pysqlx-engine VS pyodbc

[engine] - expose pysqlx-core including doc

With pysqlx-core implemented, now let's expose the features and include documentation with example usage.

  • expose methods
  • implement pydantic parse
  • include error mapping
  • support sync and async
  • include documentation function

[engine] - write unittest

Write the unitest to sync and async engine.

  • unit test to sync
  • unit test to async
  • run coverage 100%

PostgreSQL - Error when "column" is a type 'void'

Hey guys,

I try to use quaint in a simple benchmark where the database has a lag/delay in response.
So I'm using pg_sleep to simulate this delay.

But with this command returning a void, Quaint has an error.

In that case, would it be better to deserialize to null?

DB: PostgreSQL
Rust: 1.64.0
Quaint: https://github.com/prisma/quaint

Example:

// query
let sql = "SELECT pg_sleep(0.1);";

// quaint connection
let conn = Quaint::new("postgresql://postgres:postgrespw@localhost:49153").await.unwrap();

// run query
let result = conn.query_raw(sql, &[]).await.unwrap();

Error: Column type 'void' could not be deserialized from the database.

issue link: prisma/quaint#414

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.