Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge queue: embarking main (48044f0) and #282 together #285

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dynamodb/dynamodb-client.w
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pub inflight class Client impl dynamodb_types.IClient {
return unsafeCast(this.client.put(input));
}

pub inflight update(options: dynamodb_types.UpdateOptions): dynamodb_types.UpdateOutput {
let input: MutJson = options;
input.set("TableName", this.tableName);
return unsafeCast(this.client.update(input));
}

pub inflight transactWrite(options: dynamodb_types.TransactWriteOptions): dynamodb_types.TransactWriteOutput {
let transactItems = MutArray<Json> [];
for item in options.TransactItems {
Expand Down
12 changes: 12 additions & 0 deletions dynamodb/dynamodb-types.w
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ pub struct PutOptions {
ReturnValues: str?;
}

pub struct UpdateOptions {
Key: Json;
ReturnValues: str?;
ReturnConsumedCapacity: str?;
UpdateExpression: str;
ConditionExpression: str?;
ExpressionAttributeNames: Map<str>?;
ExpressionAttributeValues: Map<Json>?;
}

pub struct PutOutput {
Attributes: Json?;
}
pub struct UpdateOutput extends PutOptions {}

pub struct QueryOptions {
ConsistentRead: bool?;
Expand Down Expand Up @@ -201,6 +212,7 @@ pub inflight interface IClient {
inflight delete(options: DeleteOptions): DeleteOutput;
inflight get(options: GetOptions): GetOutput;
inflight put(options: PutOptions): PutOutput;
inflight update(options: UpdateOptions): UpdateOutput;
inflight query(options: QueryOptions): QueryOutput;
inflight scan(options: ScanOptions?): ScanOutput;
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutput;
Expand Down
4 changes: 4 additions & 0 deletions dynamodb/dynamodb.sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ pub class Table_sim impl dynamodb_types.ITable {
return this.client.put(options);
}

pub inflight update(options: dynamodb_types.UpdateOptions): dynamodb_types.UpdateOutput {
return this.client.update(options);
}

pub inflight transactWrite(options: dynamodb_types.TransactWriteOptions): dynamodb_types.TransactWriteOutput {
return this.client.transactWrite(options);
}
Expand Down
4 changes: 4 additions & 0 deletions dynamodb/dynamodb.tf-aws.w
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ pub class Table_tfaws impl dynamodb_types.ITable {
return this.client.put(options);
}

pub inflight update(options: dynamodb_types.UpdateOptions): dynamodb_types.UpdateOutput {
return this.client.update(options);
}

pub inflight transactWrite(options: dynamodb_types.TransactWriteOptions): dynamodb_types.TransactWriteOutput {
return this.client.transactWrite(options);
}
Expand Down
4 changes: 4 additions & 0 deletions dynamodb/dynamodb.w
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub class Table impl dynamodb_types.ITable {
return this.implementation.put(options);
}

pub inflight update(options: dynamodb_types.UpdateOptions): dynamodb_types.UpdateOutput {
return this.implementation.update(options);
}

pub inflight transactWrite(options: dynamodb_types.TransactWriteOptions): dynamodb_types.TransactWriteOutput {
return this.implementation.transactWrite(options);
}
Expand Down
42 changes: 42 additions & 0 deletions dynamodb/tests/update.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
bring cloud;
bring "../dynamodb.w" as dynamodb;

let table = new dynamodb.Table(
attributes: [
{
name: "id",
type: "S",
},
],
hashKey: "id",
) as "table1";

test "update" {
table.put(
Item: {
id: "1",
val1: "anything",
val2: "something"
},
);

let var response = table.query(
KeyConditionExpression: "id = :id",
ExpressionAttributeValues: {":id": "1"},
);
assert(response.Items[0]["val1"].asStr() == "anything");
assert(response.Items[0]["val2"].asStr() == "something");

table.update(
Key: { id: "1" },
UpdateExpression: "SET val2 = :v",
ExpressionAttributeValues: {":v": "everything"}
);

response = table.query(
KeyConditionExpression: "id = :id",
ExpressionAttributeValues: {":id": "1"},
);
assert(response.Items[0]["val1"].asStr() == "anything");
assert(response.Items[0]["val2"].asStr() == "everything");
}
Loading