python - alembic and getting the last inserted value -


I am using Alembic to manage my database structure.

And the primary key ID column will be an autoincrement-column. How do I ask the data in the upgrade script, so I'm sure I got the correct ID (I know that this is 1 in this specific case)?

I know how

  #creating table op.create_table ('srv_feed_return_type', sa.Column ('id', sa.Integer, primary_key = true), Sa.Column ('name', sa.String (50), null = false), bit column ('created', bit datetime, server_default = funny. Now (), faucet = incorrect), bit column ('created ('LAST_UPDATED', sa.DateTime, False = false), sa.Column ('last_updated_by', sa.String (50), faucet = false), ' For operation) # Table srv_feed_return_type = Table ('srv_feed_return_type', column ('name'), column ('created'), column ('created_by'), position ('LAST_UPDATED'), column ('last_updated_by')) #bulk insert op.bulk_insert (srv_feed_return_type, [{'name': 'dataset', 'created': datetime.now (), 'created_by': 'Asken' , 'Last_updated': datetime.now (), 'last_updated_by': 'Asken'}]   

I know that I can update but how can I seal down the whistle Using something like that?

  op.execute (srv_feed_return_type.update (). \ Where (srv_feed_return_type.c.name == op.inline_literal ('dataset')). \ Values ​​({'name': op. Inline_literal ('someelse')}  

To pass the sequence for the key column, the changes to the table schema definition will be required: sa.Column ('id', sa.Integer, sequence ('srv_feed_r_t_seq'), primary_key = true),

  #creating table op.create_table ('srv_feed_return_type', sa.Column ('id', sa.Integer, sequence ('srv_feed_r_t_seq', primary_key = true), bit column ('Name', SA string (50), Nabel = Fell), a column. ('Created', a bit time, server_default = funny.Now (), faucet = incorrect), a column ('created_by' , Sa.String (50), False = false), sa.Column ('LAST_UPDATED', sa.DateTime, False = false), sa.Column ('last_updated_by', sa.String (50), faucet = false))   

Now about how to get the ID:

op.execute and op.bulk_inert you No results returned. But you can use the same connection for these actions. After

bulk_insert or execute (table.update ...) you can choose which queries can run and records of interest in the same context Retrieve the PK ID for:

  connection = op.get_bind () r = connection.execute (srv_feed_return_type.select (). Where (...)) for row in R : Pk_id = r ['id'] "" "or some more sophisticated" ""   

You must specify the appropriate filter where the clause is to ensure that you record the identification Recent unique The altered.

Here, but the selected questions have made it difficult

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -