No project description provided
Project description
edgedb-pydantic-codegen
This library generates Python typesafe code for EdgeQL queries with Pydantic parsed models.
Install
pip install edgedb-pydantic-codegen
Usage
In an EdgeDB initialized project run
edgedb_pydantic_codegen <directory>
where <directory>
contains your *.edgeql
queries.
Generated code example
from enum import StrEnum
from edgedb import AsyncIOExecutor
from pydantic import BaseModel, TypeAdapter
EDGEQL_QUERY = r"""
with
discord_id := <int64>$discord_id,
moecoins := <optional int32>$moecoins,
blood_shards := <optional int32>$blood_shards,
updated := (
update waicolle::Player
filter .client = global client and .user.discord_id = discord_id
set {
moecoins := .moecoins + (moecoins ?? 0),
blood_shards := .blood_shards + (blood_shards ?? 0),
}
)
select updated {
game_mode,
moecoins,
blood_shards,
user: {
discord_id,
discord_id_str,
},
}
"""
class WaicolleGameMode(StrEnum):
WAIFU = "WAIFU"
HUSBANDO = "HUSBANDO"
ALL = "ALL"
class PlayerAddCoinsResultUser(BaseModel):
discord_id: int
discord_id_str: str
class PlayerAddCoinsResult(BaseModel):
game_mode: WaicolleGameMode
moecoins: int
blood_shards: int
user: PlayerAddCoinsResultUser
async def player_add_coins(
executor: AsyncIOExecutor,
*,
discord_id: int,
moecoins: int | None = None,
blood_shards: int | None = None,
) -> PlayerAddCoinsResult | None:
resp = await executor.query_single_json(
EDGEQL_QUERY,
discord_id=discord_id,
moecoins=moecoins,
blood_shards=blood_shards,
)
return TypeAdapter(PlayerAddCoinsResult | None).validate_json(resp, strict=False)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for edgedb_pydantic_codegen-2024.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858e6cdfc0aad96b6d0d11a36325cd6d2147de5f5504f4884f2f236ccfdc073b |
|
MD5 | 43478f06013923162e93d4acb26cfb1b |
|
BLAKE2b-256 | 457f4b4fe2657a635fc4800c75f4c84f7516ee4cf340b212363e7c7e2a454fef |
Close
Hashes for edgedb_pydantic_codegen-2024.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76df3b3c43c53694607da3fa4e39f77ea80ad7b8ea15c118c872243b71868749 |
|
MD5 | d64b213dfb164edee18e4f73a93ae177 |
|
BLAKE2b-256 | baf356b8801ee3df86085e434462bff921223d9101aa04e9ccfcaf894d415050 |