-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable transactions for whole endpoint execution.
- Loading branch information
Showing
11 changed files
with
245 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# SPDX-FileCopyrightText: © 2021 ChiselStrike <info@chiselstrike.com> | ||
|
||
# RUN: sh -e @file | ||
|
||
cat << EOF > "$TEMPDIR/models/types.ts" | ||
export class Person extends Chisel.ChiselEntity { | ||
name: string = ""; | ||
} | ||
EOF | ||
|
||
cat << EOF > "$TEMPDIR/endpoints/store_person.js" | ||
import { Person } from "../types.ts"; | ||
|
||
export default async function chisel(req: Request) { | ||
const req_json = await req.json(); | ||
|
||
let p = new Person(); | ||
p.name = req_json.name; | ||
await p.save(); | ||
|
||
if (req_json.command == "die with honor") { | ||
throw new InternalError("Let's see if transaction gets cancelled"); | ||
} | ||
|
||
return new Response('Mission acomplished'); | ||
} | ||
EOF | ||
|
||
cat << EOF > "$TEMPDIR/endpoints/retrieve_all.ts" | ||
import { Person } from "../models/types.ts"; | ||
|
||
export default async function chisel(req: Request) { | ||
let resp = "["; | ||
for await (let p of Person.cursor()) { | ||
resp += p.name + " "; | ||
} | ||
resp += "]"; | ||
return new Response(resp); | ||
} | ||
EOF | ||
|
||
cat << EOF > "$TEMPDIR/endpoints/write_and_read.ts" | ||
import { Person } from "../models/types.ts"; | ||
|
||
export default async function chisel(req: Request) { | ||
let p = new Person(); | ||
p.name = "ThisIsTheBestName"; | ||
await p.save(); | ||
|
||
let resp = "["; | ||
for await (let p of Person.cursor()) { | ||
resp += p.name + " "; | ||
} | ||
resp += "]"; | ||
|
||
return new Response(resp); | ||
} | ||
EOF | ||
|
||
cd "$TEMPDIR" | ||
$CHISEL apply | ||
|
||
$CURL -X POST --data '{ "name": "Adalbrecht" }' $CHISELD_HOST/dev/store_person | ||
# CHECK: Mission acomplished | ||
|
||
$CURL $CHISELD_HOST/dev/retrieve_all | ||
# CHECK: HTTP/1.1 200 OK | ||
# CHECK: [Adalbrecht ] | ||
|
||
$CURL -X POST --data '{ | ||
"name": "Ruprt", | ||
"command": "die with honor" | ||
}' $CHISELD_HOST/dev/store_person | ||
|
||
$CURL $CHISELD_HOST/dev/retrieve_all | ||
# CHECK: HTTP/1.1 200 OK | ||
# CHECK: [Adalbrecht ] | ||
|
||
$CURL -X POST $CHISELD_HOST/dev/write_and_read | ||
# CHECK: HTTP/1.1 200 OK | ||
# CHECK: [Adalbrecht, ThisIsTheBestName ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.