#NEWLINE# def insert( self , table , **kw ) : #NEWLINE# #INDENT# 'SQL insert statement helper, by default with a "returning *" clause.\n\n        Mandatory positional arguments:\n        cursor -- the cursor\n        table -- name of the table\n\n        Optional keyword arguments:\n        values -- dict with values to set (default empty)\n        filter_values -- if True, trim values so that it contains only columns found in table (default False)\n        map_values -- dict containing a mapping to be performed on \'values\' (e.g. {\'\': None}, to convert empty strings to nulls)\n        return_id -- (potentially unsafe, use with caution) if True, will select the primary key value among the returning clause\n                     elements (assuming it has a "<table>_id" name form if using a dict-like cursor, or that it\'s\n                     at position 0 otherwise)\n        debug_print -- print query before executing it (default False)\n        debug_assert -- throw assert exception (showing query), without executing it;\n                        useful for web dev debugging (default False)\n\n        ' #NEWLINE# _check_args ( 'insert' , kw . keys ( ) , ( 'values' , 'filter_values' , 'map_values' , 'return_id' , 'debug_print' , 'debug_assert' ) ) #NEWLINE# values = kw . pop ( 'values' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# return_id = kw . pop ( 'return_id' , False ) #NEWLINE# if ( not values ) : #NEWLINE# #INDENT# q = ( 'insert into %s default values returning *' % table ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if kw . pop ( 'filter_values' , False ) : #NEWLINE# #INDENT# columns = self . get_table_infos ( table ) . columns #NEWLINE# values = { c : v for ( c , v ) in values . items ( ) if ( c in columns ) } #NEWLINE# #UNINDENT# map_values = kw . pop ( 'map_values' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# values = { k : ( map_values . get ( v , v ) if isinstance ( table , collections . Hashable ) else v ) for ( k , v ) in values . items ( ) } #NEWLINE# q = 'insert into {table} ({fields}) values ({values}) returning *' #NEWLINE# q = q . format ( table = table , fields = ',' . join ( values . keys ( ) ) , values = ',' . join ( ( '%s' for v in values ) ) ) #NEWLINE# #UNINDENT# self . _exec_query ( q , values . values ( ) , ** kw ) #NEWLINE# returning = self . cursor . fetchone ( ) #NEWLINE# if return_id : #NEWLINE# #INDENT# return returning [ self . get_table_infos ( table ) . pkey ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return returning