Skip to content

Commit

Permalink
updated sqlalchemy to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Arfey committed Apr 3, 2024
1 parent 1c414c7 commit ec086a9
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ async def get_list(
count: int = await self._execute_scalar(
conn,
self.apply_filters(
query=sa.select([func.count(self._primary_key)]),
query=sa.select(func.count(self._primary_key)).select_from(self.table),
filters=filters,
)
)
else:
count: int = await self._execute_scalar(
conn,
sa.select([func.count(self._primary_key)])
sa.select(func.count()).select_from(self.table)
)
return self.create_paginator(
instances=res,
Expand Down
6 changes: 3 additions & 3 deletions example_projects/main/admin/users/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def get_list_select(self) -> sa.sql.Select:
"""
In this place you can redefine query.
"""
return sa.select([
return sa.select(
*self.table.c,
sa.type_coerce(sa.text("payload -> 'data'"), sa.Text)
.label('data')
])
)


@postgres_injector.inject
Expand All @@ -35,7 +35,7 @@ class UsersController(PostgresController, table=users):
resource = UserPostgresResource
name = 'users'
per_page = 10
upload_to = './demo/main/static'
upload_to = './example_projects/main/static'
inline_fields = ['id', 'create_at', 'is_superuser', 'array_c', 'data', ]
list_filter = ['create_at', 'is_superuser', 'id']

Expand Down
8 changes: 4 additions & 4 deletions example_projects/main/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ def recreate_tables(db_url):
async def create_users(config):
query = users.insert().values([
{
"name": "admin",
"name": "Jake Gyllenhaal",
"is_superuser": True,
"create_at": datetime.datetime.now(),
"create_at_date": datetime.datetime.today(),
"payload": {},
"avatar": "https://bit.ly/2MZJnqt",
"avatar": "https://image.tmdb.org/t/p/w200//rJdYHYNhlcOBwbPvDZVvt1xw7bi.jpg",
},
{
"name": "user",
"name": "Dionne Wudu",
"is_superuser": False,
"create_at": datetime.datetime.now(),
"create_at_date": datetime.datetime.today(),
"payload": {},
"avatar": "https://bit.ly/2MZJnqt",
"avatar": "https://image.tmdb.org/t/p/w200//gSvoRh6lRnLM0FduX3sIciTIj17.jpg",
},
])

Expand Down
Loading

0 comments on commit ec086a9

Please sign in to comment.