Exemple #1
0
    def get(self, **kwargs):
        # 整理条件
        output = kwargs.get("output", [])
        limit = kwargs.get("limit", 10)
        order_by = kwargs.get("order_by", "id desc")
        where = kwargs.get("where", {})

        # 验证
        # 验证output
        check_output_field(self.Module, output)
        # 验证order_by
        check_order_by(self.Module, order_by)
        # 验证limit
        check_limit(limit)
        # order "id desc"
        tmp_order_by = order_by.split()
        # 比较奇怪的写法
        order_by_con = getattr(getattr(self.Module, tmp_order_by[0]),
                               tmp_order_by[1])()
        # print "=========================="
        # print order_by_con
        data = db.session.query(self.Module).filter_by(
            **where).order_by(order_by_con).limit(limit).all()
        db.session.close()
        ret = process_result(data, output)
        return ret
Exemple #2
0
def get(**kwargs):
    # 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 验证
    # 验证output
    check_output_field(Idc, output)
    # 验证order_by
    order_by_list = check_order_by(Idc, order_by)

    # 验证limit
    check_limit(limit)

    data = db.session.query(Idc).filter_by(**where).order_by \
        (getattr(getattr(Idc, order_by_list[0]), order_by_list[1])()).limit(
            limit).all()
    #[ < app.models.Idc object at 0x7fe9ed3eca90 >]
    # print data
    print "sqlachemy Query 结果"
    print data
    #sqlachemy Query 结果
    #[<app.models.Idc object at 0x7f7cd80bec50>]
    db.session.close()
    ret = process_result(data, output)
    #[{'status': 1L, 'name': u'YZ', 'user_phone': u'18888888888', 'idc_name': u'\u4ea6\u5e84\u673a\u623f','rel_cabinet_num': 50L, 'email': u'*****@*****.**', 'phone': u'18519237136', 'user_interface': u'kevin','address': u'\u4ea6\u5e84\u7ecf\u6d4e\u5f00\u53d1\u533a', 'pact_cabinet_num': 60L, 'id': 1L}]
    # print ret

    return ret
Exemple #3
0
def get(**kwargs):
    # 1 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2 验证
    # 验证output
    check_output_field(Product, output)

    # 验证 order_by,字符串分割,字段是否在表中   第二个字段必须为asc desc
    order_by_list = check_order_by(Product, order_by)

    # 验证 limit 必须为数字
    check_limit(limit)

    # 验证 where 条件,先不验证
    pass

    data = db.session.query(Product).filter_by(**where)\
        .order_by(getattr(getattr(Product, order_by_list[0]), order_by_list[1])())\
        .limit(limit).all()
    db.session.close()

    # process result
    return process_result(data, output)
Exemple #4
0
def get(**kwargs):
    # 1 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2 验证
    # 验证output
    check_output_field(RaidType, output)

    # 验证 order_by,字符串分割,字段是否在表中   第二个字段必须为asc desc
    order_by_list = check_order_by(RaidType, order_by)

    # 验证 limit 必须为数字
    check_limit(limit)

    # 验证 where 条件,先不验证
    pass

    data = db.session.query(RaidType).filter_by(**where)\
        .order_by(getattr(getattr(RaidType, order_by_list[0]), order_by_list[1])())\
        .limit(limit).all()
    db.session.close()

    # process result
    return process_result(data, output)
Exemple #5
0
def get(**kwargs):
    output = kwargs.get('output', [])
    limit = kwargs.get('limit', 10)
    order_by = kwargs.get('order_by', 'id desc')
    
    check_output_field(Supplier, output)
    check_order_by(Supplier, order_by)
    check_limit(limit)
    data = db.session.query(Supplier).order_by(order_by).limit(limit).all()
    db.session.close()
    ret = process_result(data, output)
    return ret
Exemple #6
0
def get(**params):
    output = params.get('output',[])
    limit = params.get('limit',10)
    order_by = params.get('order_by','id desc')

    check_output_field(Status,output)
    check_order_by(Status,order_by)
    check_limit(limit)
    data = db.session.query(Status).order_by(order_by).limit(limit).all()
    db.session.close()

    ret = process_result(data, output)
    return ret
Exemple #7
0
def get(**params):
    output = params.get('output',[])
    limit = params.get('limit',10)
    order_by = params.get('order_by', 'id desc')

    check_output_field(Idc, output)
    check_order_by(Idc, order_by)
    check_limit(limit)
    data = db.session.query(Idc).order_by(order_by).limit(limit).all()
    db.session.close()

    ret = process_result(data, output)
    return ret
Exemple #8
0
def get(**kwargs):
    output = kwargs.get('output', [])
#    output = ['name','phone']
    print output
    limit = kwargs.get('limit', 10)
    order_by = kwargs.get('order_by', 'id desc')

    check_output_field(Server,output)
    
    check_order_by(Server, order_by)
    check_limit(limit)
    data = db.session.query(Server).order_by(order_by).limit(limit).all()
    #                      表     排序
    db.session.close()
    ret = process_result(data, output)
    return ret
Exemple #9
0
def get(**kwargs):
    output = kwargs.get('output', [])
    limit = kwargs.get('limit', 10)
    order_by = kwargs.get('order_by', 'id desc')

    check_ouput_field(Power, output)

    check_order_by(Power, order_by)
    check_limit(limit)

    data = db.session.query(Power).order_by(order_by).limit(limit).all()
    db.session.close()

    ret = process_result(data, output)

    return ret
Exemple #10
0
def get(**kwargs):
    output = kwargs.get('output', [])
    #    output = ['name','phone']
    print output
    limit = kwargs.get('limit', 10)
    order_by = kwargs.get('order_by', 'id desc')

    check_output_field(Raid, output)

    check_order_by(Raid, order_by)
    check_limit(limit)
    data = db.session.query(Raid).order_by(order_by).limit(limit).all()
    #                      表     排序
    db.session.close()
    ret = process_result(data, output)
    return ret
Exemple #11
0
def get(**kwargs):
	output = kwargs.get("output",[])
	limit = kwargs.get("limit",10)
	order_by = kwargs.get("order_by",'id desc')

	if not isinstance(output, list):
		raise Exception('output必须是列表')

	for field in output:
		if not hasattr(Idc, field):
			raise Exception("{}这个输出字段不存在".format(field))
	check_order_by(Idc,order_by)
	check_limit(limit)
	data = db.session.query(Idc).order_by(order_by).limit(limit).all()
	db.session.close()
	ret = process_result(data, output)
	return ret
Exemple #12
0
def get(**params):
    output = params.get('output', [])
    limit = params.get('limit', 10)
    order_by = params.get('order_by', 'id desc')

    if not isinstance(output, list):
        raise Exception("output必须为列表")

    for field in output:
        if not hasattr(Power, field):
            raise Exception("{}这个输出字段不存在".format(field))

    check_output_field(Power, output)
    check_order_by(Power, order_by)
    check_limit(limit)
    data = db.session.query(Power).order_by(order_by).limit(limit).all()
    db.session.close()

    ret = process_result(data, output)
    return ret
Exemple #13
0
def get(**kwargs):
    # 1. 整理条件
    output = kwargs.get("output",[])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by","id desc")
    where = kwargs.get("where",{})

    # 2. 验证
    # 3. 验证output
    check_output_field(Supplier, output)

    # 4. 验证order_by
    tmp_order_by = check_order_by(Supplier, order_by)
    # 5. 验证limit
    check_limit(limit)

    #查询
    data = db.session.query(Supplier).filter_by(**where).order_by(getattr(getattr(Supplier,tmp_order_by[0]), tmp_order_by[1])()).limit(limit).all()
    db.session.close()
    return process_result(data,output)
Exemple #14
0
def get(**params):
    output = params.get('output',[])
    limit = params.get('limit',10)
    order_by = params.get('order_by','id desc')

    if not isinstance(output, list):
        raise Exception("output必须为列表")

    for field in output:
        if not hasattr(Status,field):
            raise Exception("{}这个输出字段不存在".format(field))

    check_output_field(Status,output)
    check_order_by(Status,order_by)
    check_limit(limit)
    data = db.session.query(Status).order_by(order_by).limit(limit).all()
    db.session.close()

    ret = process_result(data, output)
    return ret
Exemple #15
0
def get(**kwargs):
    # 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 验证
    # 验证output
    check_output_field(Manufacturers, output)
    # 验证order_by
    order_by_list = check_order_by(Manufacturers, order_by)

    # 验证limit
    check_limit(limit)
    data = db.session.query(Manufacturers).filter_by(**where).order_by \
        (getattr(getattr(Manufacturers, order_by_list[0]), order_by_list[1])()).limit(limit).all()
    db.session.close()
    ret = process_result(data, output)

    return ret
Exemple #16
0
def get(**kwargs):
    # 1. 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2. 验证
    # 3. 验证output
    check_output_field(Supplier, output)

    # 4. 验证order_by
    tmp_order_by = check_order_by(Supplier, order_by)
    # 5. 验证limit
    check_limit(limit)

    #查询
    data = db.session.query(Supplier).filter_by(**where).order_by(
        getattr(getattr(Supplier, tmp_order_by[0]),
                tmp_order_by[1])()).limit(limit).all()
    db.session.close()
    return process_result(data, output)
Exemple #17
0
def get(**kwargs):
    # output: [manufacturers_name, user_interface, user_phone]
    # where: {
    #     id: 1
    # }
    # limit: 10
    # order_by: id
    # 1 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2 验证
    # 验证output
    check_output_field(Manufacturers, output)

    # 验证 order_by,字符串分割,字段是否在表中   第二个字段必须为asc desc
    order_by_list = check_order_by(Manufacturers, order_by)

    # 验证 limit 必须为数字
    check_limit(limit)

    # 验证 where 条件,先不验证
    pass

    # print callable(getattr(getattr(Manufacturers, "id"), "desc"))
    # 函数对象
    # getattr(getattr(Manufacturers, tmp_order_by[0]), tmp_order_by[1])
    # 调用函数
    # getattr(getattr(Manufacturers, tmp_order_by[0]), tmp_order_by[1])()

    data = db.session.query(Manufacturers).filter_by(**where)\
        .order_by(getattr(getattr(Manufacturers, order_by_list[0]), order_by_list[1])())\
        .limit(limit).all()
    db.session.close()

    # process result
    return process_result(data, output)
Exemple #18
0
def get(**kwargs):
    # output: [idc_name, user_interface, user_phone]
    # where: {
    #     id: 1
    # }
    # limit: 10
    # order_by: id
    # 1 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2 验证
    # 验证output
    # if not isinstance(output, list):
    #     # logging
    #     current_app.logger.warning("output 类型必须为list")
    #     raise Exception("output 类型必须为list")
    #
    # for field in output:
    #     if not hasattr(Idc, field):
    #         # logging
    #         current_app.logger.warning("{}这个output输出的字段不存在idc表中".format(field))
    #         raise Exception("{}这个output输出的字段不存在idc表中".format(field))
    check_output_field(Idc, output)

    # 验证 order_by,字符串分割,字段是否在表中   第二个字段必须为asc desc
    # tmp_order_by = order_by.split()
    # if len(tmp_order_by) != 2:
    #     # logging
    #     current_app.logger.warning("order_by 参数个数不正确")
    #     raise Exception("order_by 参数不正确")
    #
    # order_by_list = ['desc', 'asc']
    # if tmp_order_by[1].lower() not in order_by_list:
    #     # logging
    #     current_app.logger.warning("order_by 第二个参数不正确,值必须为desc或者asc")
    #     raise Exception("order_by 第二个参数不正确,值必须为desc或者asc")
    #
    # if not hasattr(Idc, tmp_order_by[0]):
    #     # logging
    #     current_app.logger.warning("排序字段 {} 不在idc表中".format(tmp_order_by[0]))
    #     raise Exception("排序字段 {} 不在idc表中".format(tmp_order_by[0]))
    order_by_list = check_order_by(Idc, order_by)

    # 验证 limit 必须为数字
    # if not str(limit).isdigit():
    #     # logging
    #     current_app.logger.warning("limit的值必须为数字")
    #     raise Exception("limit的值必须为数字")
    check_limit(limit)

    # 验证 where 条件,先不验证
    pass

    # print callable(getattr(getattr(Idc, "id"), "desc"))
    # 函数对象
    # getattr(getattr(Idc, tmp_order_by[0]), tmp_order_by[1])
    # 调用函数
    # getattr(getattr(Idc, tmp_order_by[0]), tmp_order_by[1])()

    data = db.session.query(Idc).filter_by(**where)\
        .order_by(getattr(getattr(Idc, order_by_list[0]), order_by_list[1])())\
        .limit(limit).all()
    db.session.close()

    # process result
    # ret = []
    # # print data
    # for obj in data:
    #     # print dir(obj)
    #     # print obj.__dict__
    #     if output:
    #         tmp = {}
    #         for f in output:
    #             tmp[f] = getattr(obj, f)
    #         ret.append(tmp)
    #     else:
    #         tmp = obj.__dict__
    #         tmp.pop("_sa_instance_state")
    #         ret.append(tmp)
    return process_result(data, output)
Exemple #19
0
def get(**kwargs):
    # output: [idc_name, user_interface, user_phone]
    # where: {
    #     id: 1
    # }
    # limit: 10
    # order_by: id
    # 1 整理条件
    output = kwargs.get("output", [])
    limit = kwargs.get("limit", 10)
    order_by = kwargs.get("order_by", "id desc")
    where = kwargs.get("where", {})

    # 2 验证
    # 验证output
    # if not isinstance(output, list):
    #     # logging
    #     current_app.logger.warning("output 类型必须为list")
    #     raise Exception("output 类型必须为list")
    #
    # for field in output:
    #     if not hasattr(Idc, field):
    #         # logging
    #         current_app.logger.warning("{}这个output输出的字段不存在idc表中".format(field))
    #         raise Exception("{}这个output输出的字段不存在idc表中".format(field))
    check_output_field(Idc, output)

    # 验证 order_by,字符串分割,字段是否在表中   第二个字段必须为asc desc
    # tmp_order_by = order_by.split()
    # if len(tmp_order_by) != 2:
    #     # logging
    #     current_app.logger.warning("order_by 参数个数不正确")
    #     raise Exception("order_by 参数不正确")
    #
    # order_by_list = ['desc', 'asc']
    # if tmp_order_by[1].lower() not in order_by_list:
    #     # logging
    #     current_app.logger.warning("order_by 第二个参数不正确,值必须为desc或者asc")
    #     raise Exception("order_by 第二个参数不正确,值必须为desc或者asc")
    #
    # if not hasattr(Idc, tmp_order_by[0]):
    #     # logging
    #     current_app.logger.warning("排序字段 {} 不在idc表中".format(tmp_order_by[0]))
    #     raise Exception("排序字段 {} 不在idc表中".format(tmp_order_by[0]))
    order_by_list = check_order_by(Idc, order_by)

    # 验证 limit 必须为数字
    # if not str(limit).isdigit():
    #     # logging
    #     current_app.logger.warning("limit的值必须为数字")
    #     raise Exception("limit的值必须为数字")
    check_limit(limit)

    # 验证 where 条件,先不验证
    pass

    # print callable(getattr(getattr(Idc, "id"), "desc"))
    # 函数对象
    # getattr(getattr(Idc, tmp_order_by[0]), tmp_order_by[1])
    # 调用函数
    # getattr(getattr(Idc, tmp_order_by[0]), tmp_order_by[1])()

    data = db.session.query(Idc).filter_by(**where)\
        .order_by(getattr(getattr(Idc, order_by_list[0]), order_by_list[1])())\
        .limit(limit).all()
    db.session.close()

    # process result
    # ret = []
    # # print data
    # for obj in data:
    #     # print dir(obj)
    #     # print obj.__dict__
    #     if output:
    #         tmp = {}
    #         for f in output:
    #             tmp[f] = getattr(obj, f)
    #         ret.append(tmp)
    #     else:
    #         tmp = obj.__dict__
    #         tmp.pop("_sa_instance_state")
    #         ret.append(tmp)
    return process_result(data, output)