mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2025-10-11 06:22:36 +03:00
Squashed commit of the following:
commit 70890bbec6a4eedb47a75499a13de70fb8189137 Author: Maxim Slipenko <maxim@slipenko.com> Date: Tue Aug 20 11:49:18 2024 +0300 wip: фиксит импорт commit 1ee4c92ca0e4886b445397aa139d321919fd85da Author: Maxim Slipenko <maxim@slipenko.com> Date: Tue Aug 20 11:48:55 2024 +0300 wip: добавляет message_db_logger для проверки commit a4c43fe5607e27103f03496f197292c4f942eb92 Author: Maxim Slipenko <maxim@slipenko.com> Date: Tue Aug 20 10:46:54 2024 +0300 wip: piccolo test
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .main import module_init, module_late_init, register_app_config
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"id": "experimental.database",
|
||||
"name": "Database",
|
||||
"description": "Модуль для работы с БД",
|
||||
"author": "Karkas Team",
|
||||
"version": "1.0.0",
|
||||
"privileged": true,
|
||||
"dependencies": {}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
from piccolo.conf.apps import PiccoloConfModule
|
||||
from piccolo.engine.sqlite import SQLiteEngine
|
||||
|
||||
from karkas_core.singleton import Singleton
|
||||
from karkas_piccolo.conf.apps import AppConfig, AppRegistry
|
||||
from karkas_piccolo.karkas import migrate_forward
|
||||
|
||||
# from karkas_piccolo.conf.apps import A
|
||||
|
||||
|
||||
APPS_CONFIGS = dict()
|
||||
|
||||
|
||||
def register_app_config(app_config: AppConfig):
|
||||
APPS_CONFIGS[app_config.app_name] = app_config
|
||||
|
||||
|
||||
def module_init():
|
||||
singleton = Singleton()
|
||||
singleton.storage["_database"] = dict()
|
||||
|
||||
pass
|
||||
|
||||
|
||||
async def module_late_init():
|
||||
singleton = Singleton()
|
||||
DB = SQLiteEngine(path="./db.sqlite3")
|
||||
|
||||
APP_REGISTRY = AppRegistry(apps_configs=APPS_CONFIGS)
|
||||
|
||||
module = PiccoloConfModule(name="experimental.database")
|
||||
module.DB = DB
|
||||
module.APP_REGISTRY = APP_REGISTRY
|
||||
|
||||
singleton.storage["_database"]["conf"] = module
|
||||
|
||||
await migrate_forward()
|
||||
|
||||
pass
|
@@ -0,0 +1,35 @@
|
||||
from aiogram import F, Router
|
||||
from aiogram.types import Message
|
||||
|
||||
from karkas_core.modules_system.public_api import get_module, register_router
|
||||
|
||||
from .db.tables import MessageLogger
|
||||
|
||||
|
||||
async def log_to_db(message: Message):
|
||||
await MessageLogger.insert(
|
||||
MessageLogger(
|
||||
message_text=message.text,
|
||||
chat_id=message.chat.id,
|
||||
user_id=message.from_user.id,
|
||||
)
|
||||
)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def module_init():
|
||||
from .db import APP_CONFIG
|
||||
|
||||
register_app_config = get_module("experimental.database", "register_app_config")
|
||||
register_app_config(APP_CONFIG)
|
||||
|
||||
router = Router()
|
||||
|
||||
router.message.register(log_to_db, F.text)
|
||||
|
||||
register_router(router)
|
||||
|
||||
|
||||
def module_late_init():
|
||||
pass
|
@@ -0,0 +1 @@
|
||||
from .piccolo_app import APP_CONFIG
|
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Import all of the Tables subclasses in your app here, and register them with
|
||||
the APP_CONFIG.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from karkas_piccolo.conf.apps import AppConfig
|
||||
|
||||
from .tables import MessageLogger
|
||||
|
||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
APP_CONFIG = AppConfig(
|
||||
app_name="experimental.message_db_logger",
|
||||
migrations_folder_path=os.path.join(CURRENT_DIRECTORY, "piccolo_migrations"),
|
||||
table_classes=[MessageLogger],
|
||||
migration_dependencies=[],
|
||||
commands=[],
|
||||
)
|
@@ -0,0 +1,67 @@
|
||||
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
||||
from piccolo.columns.column_types import Integer, Varchar
|
||||
from piccolo.columns.indexes import IndexMethod
|
||||
|
||||
ID = "2024-08-20T10:53:55:083110"
|
||||
VERSION = "1.16.0"
|
||||
DESCRIPTION = ""
|
||||
|
||||
|
||||
async def forwards():
|
||||
manager = MigrationManager(
|
||||
migration_id=ID,
|
||||
app_name="experimental.message_db_logger",
|
||||
description=DESCRIPTION,
|
||||
)
|
||||
|
||||
manager.add_table(
|
||||
class_name="MessageLogger",
|
||||
tablename="message_logger",
|
||||
schema=None,
|
||||
columns=None,
|
||||
)
|
||||
|
||||
manager.add_column(
|
||||
table_class_name="MessageLogger",
|
||||
tablename="message_logger",
|
||||
column_name="message_text",
|
||||
db_column_name="message_text",
|
||||
column_class_name="Varchar",
|
||||
column_class=Varchar,
|
||||
params={
|
||||
"length": 255,
|
||||
"default": "",
|
||||
"null": False,
|
||||
"primary_key": False,
|
||||
"unique": False,
|
||||
"index": False,
|
||||
"index_method": IndexMethod.btree,
|
||||
"choices": None,
|
||||
"db_column_name": None,
|
||||
"secret": False,
|
||||
},
|
||||
schema=None,
|
||||
)
|
||||
|
||||
manager.add_column(
|
||||
table_class_name="MessageLogger",
|
||||
tablename="message_logger",
|
||||
column_name="chat_id",
|
||||
db_column_name="chat_id",
|
||||
column_class_name="Integer",
|
||||
column_class=Integer,
|
||||
params={
|
||||
"default": 0,
|
||||
"null": False,
|
||||
"primary_key": False,
|
||||
"unique": False,
|
||||
"index": False,
|
||||
"index_method": IndexMethod.btree,
|
||||
"choices": None,
|
||||
"db_column_name": None,
|
||||
"secret": False,
|
||||
},
|
||||
schema=None,
|
||||
)
|
||||
|
||||
return manager
|
@@ -0,0 +1,38 @@
|
||||
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
||||
from piccolo.columns.column_types import Integer
|
||||
from piccolo.columns.indexes import IndexMethod
|
||||
|
||||
ID = "2024-08-20T11:05:48:151041"
|
||||
VERSION = "1.16.0"
|
||||
DESCRIPTION = ""
|
||||
|
||||
|
||||
async def forwards():
|
||||
manager = MigrationManager(
|
||||
migration_id=ID,
|
||||
app_name="experimental.message_db_logger",
|
||||
description=DESCRIPTION,
|
||||
)
|
||||
|
||||
manager.add_column(
|
||||
table_class_name="MessageLogger",
|
||||
tablename="message_logger",
|
||||
column_name="user_id",
|
||||
db_column_name="user_id",
|
||||
column_class_name="Integer",
|
||||
column_class=Integer,
|
||||
params={
|
||||
"default": 0,
|
||||
"null": False,
|
||||
"primary_key": False,
|
||||
"unique": False,
|
||||
"index": False,
|
||||
"index_method": IndexMethod.btree,
|
||||
"choices": None,
|
||||
"db_column_name": None,
|
||||
"secret": False,
|
||||
},
|
||||
schema=None,
|
||||
)
|
||||
|
||||
return manager
|
@@ -0,0 +1,8 @@
|
||||
from piccolo.columns import Integer, Varchar
|
||||
from piccolo.table import Table
|
||||
|
||||
|
||||
class MessageLogger(Table):
|
||||
message_text = Varchar()
|
||||
chat_id = Integer()
|
||||
user_id = Integer()
|
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "experimental.message_db_logger",
|
||||
"name": "Roles",
|
||||
"description": "Модуль для работы с БД",
|
||||
"author": "Karkas Team",
|
||||
"version": "1.0.0",
|
||||
"privileged": true,
|
||||
"dependencies": {},
|
||||
"pythonDependencies": {
|
||||
"required": {
|
||||
"karkas_piccolo": "*"
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
from karkas_core.modules_system.public_api import get_module
|
||||
|
||||
from .db import APP_CONFIG
|
||||
|
||||
register_app_config = get_module("experimental.database", "register_app_config")
|
||||
register_app_config(APP_CONFIG)
|
@@ -0,0 +1 @@
|
||||
from .piccolo_app import APP_CONFIG
|
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Import all of the Tables subclasses in your app here, and register them with
|
||||
the APP_CONFIG.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from karkas_piccolo.conf.apps import AppConfig
|
||||
|
||||
from .tables import Roles
|
||||
|
||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
APP_CONFIG = AppConfig(
|
||||
app_name="experimental.roles",
|
||||
migrations_folder_path=os.path.join(CURRENT_DIRECTORY, "piccolo_migrations"),
|
||||
table_classes=[Roles],
|
||||
migration_dependencies=[],
|
||||
commands=[],
|
||||
)
|
@@ -0,0 +1,16 @@
|
||||
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
||||
|
||||
ID = "2024-08-20T10:21:38:172313"
|
||||
VERSION = "1.16.0"
|
||||
DESCRIPTION = ""
|
||||
|
||||
|
||||
async def forwards():
|
||||
manager = MigrationManager(migration_id=ID, app_name="", description=DESCRIPTION)
|
||||
|
||||
def run():
|
||||
print(f"running {ID}")
|
||||
|
||||
manager.add_raw(run)
|
||||
|
||||
return manager
|
@@ -0,0 +1,59 @@
|
||||
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
||||
from piccolo.columns.column_types import Integer
|
||||
from piccolo.columns.indexes import IndexMethod
|
||||
|
||||
ID = "2024-08-20T10:22:08:726822"
|
||||
VERSION = "1.16.0"
|
||||
DESCRIPTION = ""
|
||||
|
||||
|
||||
async def forwards():
|
||||
manager = MigrationManager(
|
||||
migration_id=ID, app_name="experimental.roles", description=DESCRIPTION
|
||||
)
|
||||
|
||||
manager.add_table(class_name="Roles", tablename="roles", schema=None, columns=None)
|
||||
|
||||
manager.add_column(
|
||||
table_class_name="Roles",
|
||||
tablename="roles",
|
||||
column_name="role_id",
|
||||
db_column_name="role_id",
|
||||
column_class_name="Integer",
|
||||
column_class=Integer,
|
||||
params={
|
||||
"default": 0,
|
||||
"null": False,
|
||||
"primary_key": False,
|
||||
"unique": False,
|
||||
"index": False,
|
||||
"index_method": IndexMethod.btree,
|
||||
"choices": None,
|
||||
"db_column_name": None,
|
||||
"secret": False,
|
||||
},
|
||||
schema=None,
|
||||
)
|
||||
|
||||
manager.add_column(
|
||||
table_class_name="Roles",
|
||||
tablename="roles",
|
||||
column_name="chat_id",
|
||||
db_column_name="chat_id",
|
||||
column_class_name="Integer",
|
||||
column_class=Integer,
|
||||
params={
|
||||
"default": 0,
|
||||
"null": False,
|
||||
"primary_key": False,
|
||||
"unique": False,
|
||||
"index": False,
|
||||
"index_method": IndexMethod.btree,
|
||||
"choices": None,
|
||||
"db_column_name": None,
|
||||
"secret": False,
|
||||
},
|
||||
schema=None,
|
||||
)
|
||||
|
||||
return manager
|
@@ -0,0 +1,7 @@
|
||||
from piccolo.columns import Integer
|
||||
from piccolo.table import Table
|
||||
|
||||
|
||||
class Roles(Table):
|
||||
role_id = Integer()
|
||||
chat_id = Integer()
|
14
src/karkas_blocks/karkas_blocks/experimental/roles/info.json
Normal file
14
src/karkas_blocks/karkas_blocks/experimental/roles/info.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "experimental.roles",
|
||||
"name": "Roles",
|
||||
"description": "Модуль для работы с БД",
|
||||
"author": "Karkas Team",
|
||||
"version": "1.0.0",
|
||||
"privileged": true,
|
||||
"dependencies": {},
|
||||
"pythonDependencies": {
|
||||
"required": {
|
||||
"karkas_piccolo": "*"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user