Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions miniDB/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
if sys.argv[2]=='meta' and name[:4]!='meta':
continue
db.show_table(name)

5 changes: 3 additions & 2 deletions miniDB/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def select(self, columns, table_name, condition, distinct=None, order_by=None, \
return table_name._select_where(columns, condition, distinct, order_by, desc, limit)

if condition is not None:
condition_column = split_condition(condition)[0]
if((" between " not in condition) and ("not " not in condition)):
condition_column = split_condition(condition)[0]
else:
condition_column = ''

Expand Down Expand Up @@ -745,4 +746,4 @@ def drop_index(self, index_name):
warnings.warn(f'"{self.savedir}/indexes/meta_{index_name}_index.pkl" not found.')

self.save_database()

15 changes: 15 additions & 0 deletions miniDB/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,18 @@ def reverse_op(op):
'<=' : '>=',
'=' : '='
}.get(op)

def not_op(op):
'''
Return opposite of the operator given
'''
return {
'>' : '<=',
'>=' : '<',
'<' : '>=',
'<=' : '>',
'=' : '!=',
'!=' : '='
}.get(op)


18 changes: 15 additions & 3 deletions miniDB/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,20 @@ def _select_where(self, return_columns, condition=None, distinct=False, order_by
# if condition is None, return all rows
# if not, return the rows with values where condition is met for value
if condition is not None:
column_name, operator, value = self._parse_condition(condition)
column = self.column_by_name(column_name)
rows = [ind for ind, x in enumerate(column) if get_op(operator, x, value)]
if((" between " not in condition) and ("not " not in condition)):
column_name, operator, value = self._parse_condition(condition)
column = self.column_by_name(column_name)
rows = [ind for ind, x in enumerate(column) if get_op(operator, x, value)]
elif(" between " in str(condition)):

# filter
rows = [i for i in range(len(self.data))]

elif("not " in str(condition)):

# filter
rows = [i for i in range(len(self.data))]

else:
rows = [i for i in range(len(self.data))]

Expand Down Expand Up @@ -577,3 +588,4 @@ def _load_from_file(self, filename):
f.close()

self.__dict__.update(tmp_dict.__dict__)