Esempio n. 1
0
    def update_set(self, data, key):
        """
        根据条件判断有无记录,有的话就更新记录,没有的话就插入一条记录
        :return:

        """
        res = BaseHandle.update_set(self.collection, data, key)
        return res
Esempio n. 2
0
 def find_exists(self, field, value, data_field={}):
     """db.inventory.find( {"$or": [{"status": "A"}, {"qty": {"$lt": 30}}]} )
     SELECT * FROM inventory WHERE status = "A" OR qty < 30
     """
     data = dict()
     data[field] = {"$exists": value}
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 3
0
 def find_or(self, data_list, data_field={}):
     """db.inventory.find( {"$or": [{"status": "A"}, {"qty": {"$lt": 30}}]} )
     SELECT * FROM inventory WHERE status = "A" OR qty < 30
     """
     data = dict()
     data["$or"] = data_list
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 4
0
    def update_setOnInsert(self, data, key):
        """
        不存在则插入,存在则不操作
        :return:

        """
        res = BaseHandle.update_setOnInsert(self.collection, data, key)
        return res
Esempio n. 5
0
 def find_like(self, field, value, data_field={}):
     """ where key like "%audio% """
     data = dict()
     data[field] = {'$regex': '.*' + value + '.*'}
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 6
0
 def find_less(self, field, value, data_field={}):
     data = dict()
     data[field] = {"$lt": value}
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 7
0
 def find_between(self, field, value1, value2, data_field={}):
     """获取俩个值中间的数据"""
     data = dict()
     data[field] = {"$gt": value1, "$lt": value2}
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 8
0
 def find_in(self, field, item_list, data_field={}):
     """SELECT * FROM inventory WHERE status in ("A", "D")"""
     data = dict()
     data[field] = {"$in": item_list}
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 9
0
 def find_all(self, data={}, data_field={}):
     """select * from table"""
     res = BaseHandle.find_many(self.collection, data, data_field)
     return res
Esempio n. 10
0
 def find_many(self, data, data_field={}):
     """ 有多个键值的话就是 AND 的关系"""
     resIds = BaseHandle.find_many(self.collection, data, data_field)
     # 返回结果是Cursor类型相当于一个生成器
     return resIds
Esempio n. 11
0
 def find_one(self, data, data_field={}):
     resId = BaseHandle.find_one(self.collection, data, data_field)
     return resId
Esempio n. 12
0
 def insert_many(self, data_list):
     resIds = BaseHandle.insert_many(self.collection, data_list)
     return resIds
Esempio n. 13
0
 def insert_one(self, data):
     resId = BaseHandle.insert_one(self.collection, data)
     return resId
Esempio n. 14
0
 def delete_many(self, data):
     """
     删除查到的多个数据 data 是一个字典
     """
     res = BaseHandle.delete_many(self.collection, data)
     return res
Esempio n. 15
0
 def delete_one(self, data):
     """
     删除单行数据 如果有多个 则删除第一个
     """
     res = BaseHandle.delete_one(self.collection, data)
     return res