正如您所注意到的,您需要使用 PartiQL 语句来更新文档。您必须插入文档的代码片段是您更新它所需的大部分内容:您需要进行的唯一更改是您正在执行的语句。
该文档有一个 Python 教程,其中包括更新文档的示例:https ://docs.aws.amazon.com/qldb/latest/developerguide/getting-started.python.step-5.html 。
例如(来自上面的链接),以下内容将更新示例应用程序中的车辆所有者:
def update_vehicle_registration(transaction_executor, vin, document_id):
statement = "UPDATE VehicleRegistration AS r SET r.Owners.PrimaryOwner.PersonId = ? WHERE r.VIN = ?"
parameters = [document_id, convert_object_to_ion(vin)]
cursor = transaction_executor.execute_statement(statement, parameters)
try:
print_result(cursor)
logger.info('Successfully transferred vehicle with VIN: {} to new owner.'.format(vin))
except StopIteration:
raise RuntimeError('Unable to transfer vehicle, could not find registration.')
注意?
as 绑定参数的使用。这些将绑定到传递给execute_statement
(按相应顺序)的第二个参数的值。
以下是有关 PartiQL 更新语句的一些信息:https ://docs.aws.amazon.com/qldb/latest/developerguide/ql-reference.update.html 。语法是:
UPDATE table [ AS table_alias ] [ BY id_alias ]
SET element = data [, element = data, ... ]
[ WHERE condition ]
运行更新语句的结果将是受更新影响的文档 ID。