Skip to content

Commit

Permalink
fix over index creation (rethinkdb)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Mar 15, 2022
1 parent aaee76a commit 8aaf6c0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions asyncdb/providers/rethink.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,14 @@ async def createindex(
"""
CreateIndex
create and index into a field or multiple fields
--- r.table('comments').index_create('post_and_date', [r.row["post_id"], r.row["date"]]).run(conn)
"""
if self._connection:
if table in await self._engine.db(self._db).table_list().run(
self._connection
):
# check for a single index
if field:
try:
return (
await self._engine.table(table)
.index_create(field, multi=multi)
.run(self._connection)
)
except ReqlOpFailedError as err:
raise ProviderError(message=err, code=503)
elif type(fields) == list and len(fields) > 0:
if type(fields) == list and len(fields) > 0:
idx = []
for field in fields:
idx.append(self._engine.row(field))
Expand All @@ -288,8 +280,19 @@ async def createindex(
)
except (ReqlDriverError, ReqlRuntimeError):
return False
else:
try:
return (
await self._engine.table(table)
.index_create(field, multi=multi)
.run(self._connection)
)
except ReqlOpFailedError as err:
raise ProviderError(message=err, code=503)
else:
return False

create_index = createindex

async def create_table(self, table: str, pk: Union[str, List] = None):
"""
Expand Down

0 comments on commit 8aaf6c0

Please sign in to comment.