table.insert({{"id": "1"}, {"name": "Ada"}, {"birthday": "1815-12-10"}, {"age": "25"}}); # Can be json str
table.insert({{"birthday", "1791-12-26"}, {"id", "2"}, {"name", "Charles"}, {"age", "80"}});
Insert and select columns table.select({"ALL"}); # Return Both rows table.select({"name"},{"age"}); # Return name and age of all rows
def Table: def init(self, ): self.id_map = {} # {1: {name:ada, birthday: ...}}
def insert(self, entry:dict) -> bool:
entry_dict = {}
for key,value in entry:
entry_dict[key] = value # {id:1,name:ada, brthday: ...}
self.id_map[entry_dict['id']] = entry_dict # {1:{id:1,name:ada, brthday: ...}}
''' { id :[{1:0},{100:1},{150:2},{200:3}] name : [asdf,ugd,uuf,eu] age : [12,34,18,93] address: [NULL, NULL, NULL, XYZ] }
''' def select(self,*args): for arg in args: if arg == 'All': return self.id_map.values() else: column_values = []
for id, row in self.id_map.items(): column_values.append(row.get(arg,NULL)) return column_values
[ada,Charles] [25, 80]