def insert_one(self, bucket: str, event: Event) -> Event: if event.id is not None: self.replace(bucket, event.id, event) else: # We need to copy the event to avoid setting the ID on the passed event event = copy.copy(event) if self.db[bucket]: event.id = max(int(e.id or 0) for e in self.db[bucket]) + 1 else: event.id = 0 self.db[bucket].append(event) return event
def insert_one(self, bucket: str, event: Event) -> Event: # .copy is needed because otherwise mongodb inserts a _id field into the event dict_event = event.copy() dict_event = self._transform_event(dict_event) returned = self.db[bucket]["events"].insert_one(dict_event) event.id = returned.inserted_id return event
def insert_one(self, bucket: str, event: Event) -> Event: # .copy is needed because otherwise mongodb inserts a _id field into the event dict_event = event.copy() dict_event = self._transform_event(dict_event) returned = self.db[bucket]["events"].insert_one(dict_event) event.id = returned.inserted_id return event
def insert_one(self, bucket_id: str, event: Event) -> Event: e = EventModel.from_event(self.bucket_keys[bucket_id], event) e.save() b = BucketModel.get(BucketModel.key == self.bucket_keys[bucket_id]) # print(event) self.insert_update_customTables(event.data, b.type, e, bucket_id, e.timestamp, e.duration, b, False) event.id = e.id return event
def insert_one(self, bucket_id: str, event: Event) -> Event: c = self.conn.cursor() starttime = event.timestamp.timestamp() * 1000000 endtime = starttime + (event.duration.total_seconds() * 1000000) datastr = json.dumps(event.data) c.execute("INSERT INTO events(bucketrow, starttime, endtime, datastr) " + \ "VALUES ((SELECT rowid FROM buckets WHERE id = ?), ?, ?, ?)", [bucket_id, starttime, endtime, datastr]) event.id = c.lastrowid self.conditional_commit(1) return event
def insert_one(self, bucket_id: str, event: Event) -> Event: c = self.conn.cursor() starttime = event.timestamp.timestamp() * 1000000 endtime = starttime + (event.duration.total_seconds() * 1000000) datastr = json.dumps(event.data) c.execute("INSERT INTO events(bucketrow, starttime, endtime, datastr) " + "VALUES ((SELECT rowid FROM buckets WHERE id = ?), ?, ?, ?)", [bucket_id, starttime, endtime, datastr]) event.id = c.lastrowid self.conditional_commit(1) return event
def replace(self, bucket_id: str, event_id, event: Event) -> Event: self.db[bucket_id]["events"].replace_one({"_id": event_id}, self._transform_event( event.copy())) event.id = event_id return event
def insert_one(self, bucket_id: str, event: Event) -> Event: e = EventModel.from_event(self.bucket_keys[bucket_id], event) e.save() event.id = e.id return event
def insert_one(self, bucket: str, event: Event) -> Event: self.db[bucket].append(Event(**event)) event.id = len(self.db[bucket]) - 1 return event
def insert_one(self, bucket_id: str, event: Event) -> Event: e = EventModel.from_event(self.bucket_keys[bucket_id], event) e.save() event.id = e.id return event
def replace(self, bucket_id: str, event_id, event: Event) -> bool: self.db[bucket_id]["events"].replace_one({"_id": event_id}, self._transform_event(event.copy())) event.id = event_id return True
def insert_one(self, bucket: str, event: Event) -> Event: self.db[bucket].append(Event(**event)) event.id = len(self.db[bucket]) - 1 return event