Skip to content

Commit

Permalink
select_keys supported in get
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <praneeth@bpraneeth.com>
  • Loading branch information
bedapudi6788 committed Oct 21, 2023
1 parent ef04b67 commit ab154d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions liteindex/defined_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,22 @@ def update(self, data):
self._connection.executemany(sql, transactions)
self._connection.commit()

def get(self, ids):
def get(self, ids, select_keys=[]):
if isinstance(ids, str):
ids = [ids]

if not select_keys:
select_keys = list(self.original_key_to_key_hash.values())
else:
if [k for k in select_keys if k not in self.original_key_to_key_hash]:
raise ValueError(
f"Invalid select_keys: {[k for k in select_keys if k not in self.original_key_to_key_hash]}"
)

select_keys = [self.original_key_to_key_hash[k] for k in select_keys]

# Prepare the SQL command
columns = ", ".join([f'"{h}"' for h in self.original_key_to_key_hash.values()])
columns = ", ".join([f'"{h}"' for h in select_keys])
column_str = "id, " + columns # Update this to include `id`

# Format the ids for the where clause
Expand All @@ -261,7 +271,7 @@ def get(self, ids):
for row in self._connection.execute(sql, ids).fetchall():
record = {
self.key_hash_to_original_key[h]: val
for h, val in zip(self.original_key_to_key_hash.values(), row[1:])
for h, val in zip(select_keys, row[1:])
if val is not None
}
for k, v in record.items():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = "praneeth@bpraneeth.com"
AUTHOR = "BEDAPUDI PRANEETH"
REQUIRES_PYTHON = ">=3.6.0"
VERSION = "0.0.2.dev3"
VERSION = "0.0.2.dev4"

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down

0 comments on commit ab154d0

Please sign in to comment.