def find_by_template(self,
                         template,
                         field_list=None,
                         limit=None,
                         offset=None,
                         order_by=None):
        """

        :param template: A dictionary of the form { "field1" : value1, "field2": value2, ...}
        :param field_list: A list of request fields of the form, ['fielda', 'fieldb', ...]
        :param limit: Do not worry about this for now.
        :param offset: Do not worry about this for now.
        :param order_by: Do not worry about this for now.
        :return: A list containing dictionaries. A dictionary is in the list representing each record
            that matches the template. The dictionary only contains the requested fields.
        """
        sql, args = SQLHelper.create_select(table_name=self.table_name,
                                            template=template,
                                            fields=field_list)
        res, data = SQLHelper.run_q(sql=sql,
                                    args=args,
                                    conn=self.connect_info,
                                    commit=self.commit)
        if not data:
            return None
        else:
            return data[0]
Beispiel #2
0
    def find_by_primary_key(self, key_fields, field_list=None):
        """

        :param key_fields: The list with the values for the key_columns, in order, to use to find a record.
        :param field_list: A subset of the fields of the record to return.
        :return: None, or a dictionary containing the requested fields for the record identified
            by the key.
        """

        cox = pymysql.connect(**self.connect_info)
        template = dict(zip(self.key_columns, key_fields))
        sql, args = SQLHelper.create_select(self.table_name, template,
                                            field_list)
        num, res = SQLHelper.run_q(sql, args, cox)
    def find_by_primary_key(self, key_fields, field_list=None):
        """

        :param key_fields: The list with the values for the key_columns, in order, to use to find a record.
        :param field_list: A subset of the fields of the record to return.
        :return: None, or a dictionary containing the requested fields for the record identified
            by the key.
        """
        template = {k: v for k, v in zip(self.key_columns, key_fields)}
        sql, args = SQLHelper.create_select(table_name=self.table_name,
                                            template=template,
                                            fields=field_list)
        res, data = SQLHelper.run_q(sql=sql,
                                    args=args,
                                    conn=self.connect_info,
                                    commit=self.commit)
        if not data:
            return None
        else:
            return data[0]
Beispiel #4
0
 def get_rows(self):
     cox = pymysql.connect(**self.connect_info)
     sql, args = SQLHelper.create_select(self.table_name, None, None)
     num, res = SQLHelper.run_q(sql, args, cox)
     return res