wip
This commit is contained in:
parent
839cbd0dc0
commit
a9ee4a2bd8
7 changed files with 199 additions and 31 deletions
|
|
@ -8,7 +8,13 @@ import typer
|
|||
from learn_sql_model.config import Config, get_config
|
||||
from learn_sql_model.factories.hero import HeroFactory
|
||||
from learn_sql_model.factories.pet import PetFactory
|
||||
from learn_sql_model.models.hero import Hero, HeroCreate
|
||||
from learn_sql_model.models.hero import (
|
||||
Hero,
|
||||
HeroCreate,
|
||||
HeroDelete,
|
||||
HeroRead,
|
||||
HeroUpdate,
|
||||
)
|
||||
|
||||
hero_app = typer.Typer()
|
||||
|
||||
|
|
@ -26,7 +32,7 @@ def get(
|
|||
) -> Union[Hero, List[Hero]]:
|
||||
"get one hero"
|
||||
config.init()
|
||||
hero = Hero().get(id=id)
|
||||
hero = HeroRead.get(id=id, config=config)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
|
||||
|
|
@ -34,10 +40,13 @@ def get(
|
|||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def list(
|
||||
where: Optional[str] = None,
|
||||
config: Config = None,
|
||||
offset: int = 0,
|
||||
limit: Optional[int] = None,
|
||||
) -> Union[Hero, List[Hero]]:
|
||||
"get one hero"
|
||||
hero = Hero().get()
|
||||
hero = HeroRead.list(config=config, where=where, offset=offset, limit=limit)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
|
||||
|
|
@ -49,9 +58,42 @@ def create(
|
|||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
config.init()
|
||||
# config.init()
|
||||
hero = hero.post(config=config)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
# config.init()
|
||||
# with Session(config.database.engine) as session:
|
||||
# db_hero = Hero.from_orm(hero)
|
||||
# session.add(db_hero)
|
||||
# session.commit()
|
||||
# session.refresh(db_hero)
|
||||
# return db_hero
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def update(
|
||||
hero: HeroUpdate,
|
||||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
hero = hero.update(config=config)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def delete(
|
||||
hero: HeroDelete,
|
||||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
# config.init()
|
||||
hero = hero.delete(config=config)
|
||||
return hero
|
||||
# Console().print(hero)
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import alembic
|
||||
from alembic.config import Config
|
||||
import typer
|
||||
from alembic.config import Config
|
||||
from copier import run_auto
|
||||
|
||||
from learn_sql_model.cli.common import verbose_callback
|
||||
|
||||
|
|
@ -19,13 +20,24 @@ def model(
|
|||
|
||||
|
||||
@model_app.command()
|
||||
def create_revision(
|
||||
def create(
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
message: str = typer.Option(
|
||||
template=Path('templates/model')
|
||||
run_auto(template, Path('.'))
|
||||
|
||||
|
||||
@ model_app.command()
|
||||
def create_revision(
|
||||
verbose: bool=typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
message: str=typer.Option(
|
||||
prompt=True,
|
||||
),
|
||||
):
|
||||
|
|
@ -39,23 +51,23 @@ def create_revision(
|
|||
alembic.command.upgrade(config=alembic_cfg, revision="head")
|
||||
|
||||
|
||||
@model_app.command()
|
||||
@ model_app.command()
|
||||
def checkout(
|
||||
verbose: bool = typer.Option(
|
||||
verbose: bool=typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
revision: str = typer.Option("head"),
|
||||
revision: str=typer.Option("head"),
|
||||
):
|
||||
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
alembic.command.upgrade(config=alembic_cfg, revision="head")
|
||||
|
||||
|
||||
@model_app.command()
|
||||
@ model_app.command()
|
||||
def populate(
|
||||
verbose: bool = typer.Option(
|
||||
verbose: bool=typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue