feat: add useful query helpers for insert and update (#2020)

* feat: add useful query helpers for insert and update

i saw this bits of code all over the codebase, this `helpers.py`
tries to abstract that away and make it more readable.
This commit is contained in:
dni ⚡ 2023-10-16 13:27:59 +02:00 committed by GitHub
parent c8661ffcf3
commit dbf687c47a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import pytest
from pydantic import BaseModel
from lnbits.helpers import (
insert_query,
update_query,
)
class TestModel(BaseModel):
id: int
name: str
test = TestModel(id=1, name="test")
@pytest.mark.asyncio
async def test_helpers_insert_query():
q = insert_query("test_helpers_query", test)
assert q == "INSERT INTO test_helpers_query (id, name) VALUES (?, ?)"
@pytest.mark.asyncio
async def test_helpers_update_query():
q = update_query("test_helpers_query", test)
assert q == "UPDATE test_helpers_query SET id = ?, name = ? WHERE id = ?"