Skip to main content

Создание файлов конфигурация

Project description

Подготовка

Для работы с БД я создал библиотеку на основе SqlAlchemy.

Главно, что нужно сделать для работы с этой библиотекой, это заранее вызвать конструктор класса SQL, который создаст подключение к СУБД

SQL(SqlUrlConnect.СУБД(user='', password='', host='', name_db=''))
  • SqlUrlConnect - Класс с шаблонами формирования url для подключения к СУБД

Использование

Использование в асинхронной Функции/Методе

import asyncio
from mg_sql.sql_async import SqlUrlConnect
from mg_sql.sql_async.base import SQL
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncConnection, AsyncEngine

@SQL.get_session_decor
async def ReadDB(_session: AsyncSession):
    res = await SQL.read_execute_raw_sql(_session, raw_sql=""" SQL ЗАПРОС = :ключ """, params={'ключ':Значение})

asyncio.run(ReadDB())
  • raw_sql='' - SQL запрос
  • params:dict[str,Any] - Параметры в шаблонные

Создание таблиц

import asyncio
from mg_sql.sql_async.base import SQL
from mg_sql.sql_async.model_logic import RawSqlModel

class ИмяТаблицы(RawSqlModel):
    """Пользователи"""
    table_name = 'ИмяТаблицы'

    @classmethod
    def create_table(cls) -> str:
        return """
CREATE TABLE ИмяТаблицы (
 id INTEGER,
 user_id INTEGER,
);
CREATE UNIQUE INDEX ix_users_vk_user_id ON users_vk (user_id);
    """

asyncio.run(SQL.create_models(
    [ИмяТаблицы]
))

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

mg_sql-0.0.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

mg_sql-0.0.1-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file mg_sql-0.0.1.tar.gz.

File metadata

  • Download URL: mg_sql-0.0.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.0rc1 Linux/5.15.0-56-generic

File hashes

Hashes for mg_sql-0.0.1.tar.gz
Algorithm Hash digest
SHA256 38faae5a644c044b06047203de08622ede39555f2b863bac82a27bc227a6552d
MD5 e97643d2865272156d02f3421996a01d
BLAKE2b-256 1e3d746944431df21595ff7d08f5d7947cec7eb28a6b532438eea6342a071e99

See more details on using hashes here.

File details

Details for the file mg_sql-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mg_sql-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.0rc1 Linux/5.15.0-56-generic

File hashes

Hashes for mg_sql-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdf6a823d3517e43f160eafa7fa22cd0e0b6cc816611526435a14f6efea66f32
MD5 ff64aadd9a3bb3819bf3ce6158bb745f
BLAKE2b-256 fdc593976d30242d900b953a106af56e3ddd13d488efd361cf3d7f76ffc6d653

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