def datastore_upsert(context, data_dict):
 schema = context.get('schema', dsschema.datastore_upsert_schema())
 records = data_dict.pop('records', None)
 (data_dict, errors) = _validate(data_dict, schema, context)
 if records:
  data_dict['records'] = records
 if errors:
  raise p.toolkit.ValidationError(errors)
 p.toolkit.check_access('datastore_upsert', context, data_dict)
 if (not data_dict.pop('force', False)):
  resource_id = data_dict['resource_id']
  _check_read_only(context, resource_id)
 data_dict['connection_url'] = config['ckan.datastore.write_url']
 res_id = data_dict['resource_id']
 resources_sql = sqlalchemy.text(u'SELECT 1 FROM "_table_metadata"\n                                        WHERE name = :id AND alias_of IS NULL')
 results = db._get_engine(data_dict).execute(resources_sql, id=res_id)
 res_exists = (results.rowcount > 0)
 if (not res_exists):
  raise p.toolkit.ObjectNotFound(p.toolkit._(u'Resource "{0}" was not found.'.format(res_id)))
 result = db.upsert(context, data_dict)
 result.pop('id', None)
 result.pop('connection_url')
 return result

def datastore_upsert ( context , data_dict ) : schema = context . get ( 'schema' , dsschema . datastore_upsert_schema ( ) ) records = data_dict . pop ( 'records' , None ) ( data_dict , errors ) = _validate ( data_dict , schema , context ) if records : data_dict [ 'records' ] = records if errors : raise p . toolkit . ValidationError ( errors ) p . toolkit . check_access ( 'datastore_upsert' , context , data_dict ) if ( not data_dict . pop ( 'force' , False ) ) : resource_id = data_dict [ 'resource_id' ] _check_read_only ( context , resource_id ) data_dict [ 'connection_url' ] = config [ 'ckan.datastore.write_url' ] res_id = data_dict [ 'resource_id' ] resources_sql = sqlalchemy . text ( u'SELECT 1 FROM "_table_metadata"\n                                        WHERE name = :id AND alias_of IS NULL' ) results = db . _get_engine ( data_dict ) . execute ( resources_sql , id = res_id ) res_exists = ( results . rowcount > 0 ) if ( not res_exists ) : raise p . toolkit . ObjectNotFound ( p . toolkit . _ ( u'Resource "{0}" was not found.' . format ( res_id ) ) ) result = db . upsert ( context , data_dict ) result . pop ( 'id' , None ) result . pop ( 'connection_url' ) return result
updates or inserts into a table in the datastore the datastore_upsert api action allows you to add or edit records to an existing datastore resource .