Skip to main content

A MySQL driver adaptor for aiosql

Project description

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

aiosql-mysql

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Thanks

About The Project

aiosql-mysql is a database adaptor intended to allow the use of asyncmy with aiosql.

Warning:

This project is in early developement. The PyMySQL adaptor works but is not fully tested. AsyncMy is not implimented and working at this time, please check back later.

Getting Started

For information about cloning and dev setup see: Contributing

Usage

This is example is adapted from aiosql's readme.

users.sql

-- name: get-user-by-username^
SELECT *
FROM users
WHERE username = :username;

-- name: create_users#
CREATE TABLE users ( userid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                     username VARCHAR(100),
                     firstname VARCHAR(100),
                     lastname VARCHAR(100)
);

-- name: insert_bob!
INSERT INTO users (username, firstname, lastname)
VALUES ('bob', 'bob', 'smith');

Blocking execution

Indexing a document adds it to or updates it in the search store.

import aiosql
import pymysql
from aiosql_mysql import PyMySQLAdaptor

conn = pymysql.connect(
        host="127.0.0.1",
        port=3306,
        user="root",
        password="password",
        database="ExampleDb",
        cursorclass=pymysql.cursors.DictCursor,
    )

queries = aiosql.from_path("./users.sql", PyMySQLAdaptor)
queries.create_users(conn)
queries.insert_bob(conn)
result = queries.get_user_by_username(conn, username="bob")
print(result)
# {'userid': 1, 'username': 'bob', 'firstname': 'bob', 'lastname': 'smith'}

For a more detailed and complete version of the above example see pymysql_example.py & users.sql

Async execution

import aiosql
import asyncmy
from aiosql_mysql import AsyncMySQLAdapter

queries = aiosql.from_path("./users.sql", AsyncMySQLAdapter)

async def main():
    conn = await asyncmy.connect(
        host="127.0.0.1",
        port=3306,
        user="root",
        password="password",
        database="ExampleDb",
    )

    await queries.create_users(conn)
    await queries.insert_user(conn,user_name='sbob', first_name='Bob', last_name='Smith')
    result = await queries.get_user_by_username(conn, username="sbob")
    print(result)


if __name__ == "__main__":
  import asyncio

  asyncio.run(main())
  # {'userid': 1, 'username': 'sbob', 'firstname': 'Bob', 'lastname': 'Smith'}

For a more detailed and complete version of the above example see asyncmy_example.py & users.sql

Contributing

See the open issues for a list of proposed features (and known issues).

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  1. execute: py.test --cov-report xml:cov.xml --cov
  2. Commit your Changes (git commit -m 'Add some AmazingFeature')
  3. Push to the Branch (git push origin feature/AmazingFeature)
  4. Open a Pull Request

Cloning / Development setup

  1. Clone the repo and install
    git clone https://github.com/kajuberdut/aiosql-mysql.git
    cd aiosql-mysql
    pipenv install --dev
    
  2. Run tests
    pipenv shell
    ward
    

For more about pipenv see: Pipenv Github

License

Distributed under the MIT. See LICENSE for more information.

Contact

Patrick Shechet - patrick.shechet@gmail.com

Project Link: https://github.com/kajuberdut/aiosql-mysql

Thanks

This library would be pointless without:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiosql_mysql-0.0.1a1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

aiosql_mysql-0.0.1a1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file aiosql_mysql-0.0.1a1.tar.gz.

File metadata

  • Download URL: aiosql_mysql-0.0.1a1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for aiosql_mysql-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 71c12be2186cbf4cadbf2a778f6fed5c89322107d82b549467f158f6d7dbab9f
MD5 99adc31e3ac6f807b3bb8d3cc5e04a89
BLAKE2b-256 414a7776d86531835581a913df482dba4d7eb61483be91b60db60ce7a1d144cd

See more details on using hashes here.

File details

Details for the file aiosql_mysql-0.0.1a1-py3-none-any.whl.

File metadata

  • Download URL: aiosql_mysql-0.0.1a1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for aiosql_mysql-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6e9e629e83f21941baf55f015a4a9ed5b7c2800ca1cd0e96504b49c2fc6de48
MD5 aeb18ddf0b45faf2217a98f1f03a503d
BLAKE2b-256 f1fe5ec130309ae671ff7f8d8aa1ed26e154cf38a9fb92979a1c8d227c21e957

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page