labpack/databases/sql.py
def _prepare_record(self, record_details):

        ''' a helper method for converting a record to column-based fields '''

        # add fields to create request
        fields = {}
        for key, value in self.model.keyMap.items():
            record_key = key[1:]
            if record_key:
                if self.item_key.findall(record_key):
                    pass
                else:
                    if value['value_datatype'] in ('boolean', 'string', 'number'):
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = results[0]
                        except:
                            if self.default_values:
                                results = self.model._walk(key, self.default)
                                fields[record_key] = results[0]
                    elif value['value_datatype'] in 'list':
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = pickle.dumps(results[0])
                        except:
                            if self.default_values:
                                results = self.model._walk(key, self.default)
                                fields[record_key] = pickle.dumps(results[0])
                    elif key in self.empty_maps:
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = pickle.dumps(results[0])
                        except:
                            if self.default_values:
                                fields[record_key] = pickle.dumps({})

        # add id field if missing
        lab = self.labID()
        uid = lab.id24
        if not 'id' in fields.keys():
            if '.id' in self.model.keyMap.keys():
                if self.model.keyMap['.id']['value_datatype'] == 'number':
                    # TODO auto increment record

                    # sqlite and postgres do not support > 64-bit integers
                    if self.database_dialect in ('sqlite','postgres'):
                        from labpack.randomization.randomlab import random_integer
                        fields['id'] = random_integer(0, 2 ** 63)
                    # produce a non-colliding integer derived from uuid
                    else:
                        import binascii
                        lab_hex = binascii.hexlify(lab.bytes_18).decode()
                        fields['id'] = int(lab_hex, 16)
                else:
                    fields['id'] = uid
            else:
                fields['id'] = uid

        return fields
 a helper method for converting a record to column-based fields 
a helper method for converting a record to column-based fields
a helper method for converting a record to column - based fields
def _prepare_record(self, record_details):
        fields = {}
        for key, value in self.model.keyMap.items():
            record_key = key[1:]
            if record_key:
                if self.item_key.findall(record_key):
                    pass
                else:
                    if value['value_datatype'] in ('boolean', 'string', 'number'):
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = results[0]
                        except:
                            if self.default_values:
                                results = self.model._walk(key, self.default)
                                fields[record_key] = results[0]
                    elif value['value_datatype'] in 'list':
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = pickle.dumps(results[0])
                        except:
                            if self.default_values:
                                results = self.model._walk(key, self.default)
                                fields[record_key] = pickle.dumps(results[0])
                    elif key in self.empty_maps:
                        try:
                            results = self.model._walk(key, record_details)
                            fields[record_key] = pickle.dumps(results[0])
                        except:
                            if self.default_values:
                                fields[record_key] = pickle.dumps({})
        lab = self.labID()
        uid = lab.id24
        if not 'id' in fields.keys():
            if '.id' in self.model.keyMap.keys():
                if self.model.keyMap['.id']['value_datatype'] == 'number':
                    if self.database_dialect in ('sqlite','postgres'):
                        from labpack.randomization.randomlab import random_integer
                        fields['id'] = random_integer(0, 2 ** 63)
                    else:
                        import binascii
                        lab_hex = binascii.hexlify(lab.bytes_18).decode()
                        fields['id'] = int(lab_hex, 16)
                else:
                    fields['id'] = uid
            else:
                fields['id'] = uid
        return fields
def _prepare_record ( self , record_details ) : fields = { } for key , value in self . model . keyMap . items ( ) : record_key = key [ 1 : ] if record_key : if self . item_key . findall ( record_key ) : pass else : if value [ 'value_datatype' ] in ( 'boolean' , 'string' , 'number' ) : try : results = self . model . _walk ( key , record_details ) fields [ record_key ] = results [ 0 ] except : if self . default_values : results = self . model . _walk ( key , self . default ) fields [ record_key ] = results [ 0 ] elif value [ 'value_datatype' ] in 'list' : try : results = self . model . _walk ( key , record_details ) fields [ record_key ] = pickle . dumps ( results [ 0 ] ) except : if self . default_values : results = self . model . _walk ( key , self . default ) fields [ record_key ] = pickle . dumps ( results [ 0 ] ) elif key in self . empty_maps : try : results = self . model . _walk ( key , record_details ) fields [ record_key ] = pickle . dumps ( results [ 0 ] ) except : if self . default_values : fields [ record_key ] = pickle . dumps ( { } ) lab = self . labID ( ) uid = lab . id24 if not 'id' in fields . keys ( ) : if '.id' in self . model . keyMap . keys ( ) : if self . model . keyMap [ '.id' ] [ 'value_datatype' ] == 'number' : if self . database_dialect in ( 'sqlite' , 'postgres' ) : from labpack . randomization . randomlab import random_integer fields [ 'id' ] = random_integer ( 0 , 2 ** 63 ) else : import binascii lab_hex = binascii . hexlify ( lab . bytes_18 ) . decode ( ) fields [ 'id' ] = int ( lab_hex , 16 ) else : fields [ 'id' ] = uid else : fields [ 'id' ] = uid return fields
a helper method for converting a record to column-based fields
a helper method for converting a record to column - based fields
''' a helper method for converting a record to column-based fields ''' # add fields to create request # add id field if missing # TODO auto increment record # sqlite and postgres do not support > 64-bit integers # produce a non-colliding integer derived from uuid
self
record_details