labpack/databases/google/datastore.py
def create(self, record):

        '''
            a method to create a new record in the table

            NOTE:   this class uses the id field as the primary key for all records
                    if record includes an id field that is an integer, float
                    or string, then it will be used as the primary key. 

            NOTE:   if the id field is missing, a unique 24 character url safe 
                    string will be created for the id field and included in the 
                    record. if the id field == 0.0, then datastore will assign a 
                    randomly generated 16 digit numerical id
            
            NOTE:   key length is a significant component of the size of storing a
                    record. the built in datastore id take up 8 bytes while an id
                    string takes up bytes = len(id) + 1. in addition, all keys have
                    an additional 16 byte overhead and the record id is reused for
                    each index twice, once for ascending and once for descending
                    order. 

            NOTE:   record fields which do not exist in the record_schema or 
                    whose value do not match the requirements of the record_schema
                    will throw an InputValidationError

            NOTE:   list fields are stringified using json before they are saved 
                    to the datastore and are not possible to search using query
                    statements. it is recommended that lists be stored instead as
                    separate tables

        :param record: dictionary with record fields 
        :return: string with id for record
        '''

        title = '%s.create' % self.__class__.__name__

        # validate inputs
        details = self.model.validate(record, object_title='%s(record={...})' % title)

        # prepare fields for put request
        fields = self._prepare_record(details)

        # prepare key for datastore
        # https://cloud.google.com/datastore/docs/concepts/entities#assigning_identifiers
        key = None
        record_id = None
        generated = False
        if isinstance(fields['id'], int) or isinstance(fields['id'], float):
            if not fields['id']:
                key = self.client.key(self.kind)
                generated = True
        if not generated:
            record_id = fields['id']
            key = self.client.key(self.kind, record_id)
        del fields['id']

        # prepare record for insertion
        # https://cloud.google.com/datastore/docs/concepts/entities
        exclusions = set(fields.keys()) - self.store_indices
        kwargs = {'key': key}
        if exclusions:
            kwargs['exclude_from_indexes'] = list(exclusions)
        entity = datastore.Entity(**kwargs)
        entity.update(fields)

        # send put request
        self.client.put(entity)

        # return primary key
        if generated:
            record_id = entity.key._flat_path[-1]
        self.printer('Record %s created.' % record_id)

        return record_id

            a method to create a new record in the table

            NOTE:   this class uses the id field as the primary key for all records
                    if record includes an id field that is an integer, float
                    or string, then it will be used as the primary key. 

            NOTE:   if the id field is missing, a unique 24 character url safe 
                    string will be created for the id field and included in the 
                    record. if the id field == 0.0, then datastore will assign a 
                    randomly generated 16 digit numerical id
            
            NOTE:   key length is a significant component of the size of storing a
                    record. the built in datastore id take up 8 bytes while an id
                    string takes up bytes = len(id) + 1. in addition, all keys have
                    an additional 16 byte overhead and the record id is reused for
                    each index twice, once for ascending and once for descending
                    order. 

            NOTE:   record fields which do not exist in the record_schema or 
                    whose value do not match the requirements of the record_schema
                    will throw an InputValidationError

            NOTE:   list fields are stringified using json before they are saved 
                    to the datastore and are not possible to search using query
                    statements. it is recommended that lists be stored instead as
                    separate tables

        :param record: dictionary with record fields 
        :return: string with id for record
        
a method to create a new record in the table
NOTE:   this class uses the id field as the primary key for all records
if record includes an id field that is an integer, float
or string, then it will be used as the primary key.

if the id field is missing, a unique 24 character url safe
string will be created for the id field and included in the
record. if the id field == 0.0, then datastore will assign a
randomly generated 16 digit numerical id

key length is a significant component of the size of storing a
record. the built in datastore id take up 8 bytes while an id
string takes up bytes = len(id) + 1. in addition, all keys have
an additional 16 byte overhead and the record id is reused for
each index twice, once for ascending and once for descending
order.

record fields which do not exist in the record_schema or
whose value do not match the requirements of the record_schema
will throw an InputValidationError

list fields are stringified using json before they are saved
to the datastore and are not possible to search using query
statements. it is recommended that lists be stored instead as
separate tables
a method to create a new record in the table NOTE : this class uses the id field as the primary key for all records if record includes an id field that is an integer float or string then it will be used as the primary key . if the id field is missing a unique 24 character url safe string will be created for the id field and included in the record . if the id field == 0 . 0 then datastore will assign a randomly generated 16 digit numerical id key length is a significant component of the size of storing a record . the built in datastore id take up 8 bytes while an id string takes up bytes = len ( id ) + 1 . in addition all keys have an additional 16 byte overhead and the record id is reused for each index twice once for ascending and once for descending order . record fields which do not exist in the record_schema or whose value do not match the requirements of the record_schema will throw an InputValidationError list fields are stringified using json before they are saved to the datastore and are not possible to search using query statements . it is recommended that lists be stored instead as separate tables
def create(self, record):
        title = '%s.create' % self.__class__.__name__
        details = self.model.validate(record, object_title='%s(record={...})' % title)
        fields = self._prepare_record(details)
        key = None
        record_id = None
        generated = False
        if isinstance(fields['id'], int) or isinstance(fields['id'], float):
            if not fields['id']:
                key = self.client.key(self.kind)
                generated = True
        if not generated:
            record_id = fields['id']
            key = self.client.key(self.kind, record_id)
        del fields['id']
        exclusions = set(fields.keys()) - self.store_indices
        kwargs = {'key': key}
        if exclusions:
            kwargs['exclude_from_indexes'] = list(exclusions)
        entity = datastore.Entity(**kwargs)
        entity.update(fields)
        self.client.put(entity)
        if generated:
            record_id = entity.key._flat_path[-1]
        self.printer('Record %s created.' % record_id)
        return record_id
def create ( self , record ) : title = '%s.create' % self . __class__ . __name__ details = self . model . validate ( record , object_title = '%s(record={...})' % title ) fields = self . _prepare_record ( details ) key = None record_id = None generated = False if isinstance ( fields [ 'id' ] , int ) or isinstance ( fields [ 'id' ] , float ) : if not fields [ 'id' ] : key = self . client . key ( self . kind ) generated = True if not generated : record_id = fields [ 'id' ] key = self . client . key ( self . kind , record_id ) del fields [ 'id' ] exclusions = set ( fields . keys ( ) ) - self . store_indices kwargs = { 'key' : key } if exclusions : kwargs [ 'exclude_from_indexes' ] = list ( exclusions ) entity = datastore . Entity ( ** kwargs ) entity . update ( fields ) self . client . put ( entity ) if generated : record_id = entity . key . _flat_path [ - 1 ] self . printer ( 'Record %s created.' % record_id ) return record_id
a method to create a new record in the table
NOTE:   this class uses the id field as the primary key for all records
if record includes an id field that is an integer, float
or string, then it will be used as the primary key.
a method to create a new record in the table NOTE : this class uses the id field as the primary key for all records if record includes an id field that is an integer float or string then it will be used as the primary key .
'''
            a method to create a new record in the table

            NOTE:   this class uses the id field as the primary key for all records
                    if record includes an id field that is an integer, float
                    or string, then it will be used as the primary key. 

            NOTE:   if the id field is missing, a unique 24 character url safe 
                    string will be created for the id field and included in the 
                    record. if the id field == 0.0, then datastore will assign a 
                    randomly generated 16 digit numerical id
            
            NOTE:   key length is a significant component of the size of storing a
                    record. the built in datastore id take up 8 bytes while an id
                    string takes up bytes = len(id) + 1. in addition, all keys have
                    an additional 16 byte overhead and the record id is reused for
                    each index twice, once for ascending and once for descending
                    order. 

            NOTE:   record fields which do not exist in the record_schema or 
                    whose value do not match the requirements of the record_schema
                    will throw an InputValidationError

            NOTE:   list fields are stringified using json before they are saved 
                    to the datastore and are not possible to search using query
                    statements. it is recommended that lists be stored instead as
                    separate tables

        :param record: dictionary with record fields 
        :return: string with id for record
        ''' # validate inputs # prepare fields for put request # prepare key for datastore # https://cloud.google.com/datastore/docs/concepts/entities#assigning_identifiers # prepare record for insertion # https://cloud.google.com/datastore/docs/concepts/entities # send put request # return primary key
string with id for record
string with id for record
self
record
dictionary with record fields
dictionary with record fields