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
int f() { | |
return 0; | |
} |
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
// Validating emails with email-validator. | |
// Validation happens inline, straight inside the arrow function | |
const user = await User.findOne(user => user.name == "Glauber Costa" && | |
user.age >= 40 && | |
validate(user.email)); | |
return new Response(user?.email ?? "not found"); | |
// Same code, but now splitting database and runtime code out-of-line. | |
// The results are equivalent in ChiselStrike. | |
const user = await User.findOne(user => user.name == "Glauber Costa" && user.age >= 40); |
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
// model definition | |
export class User extends ChiselEntity { | |
name: string = ""; | |
email: string = ""; | |
age: number = 0; | |
} | |
// endpoint code | |
const user = await User.findOne(user => user.name == "Glauber Costa" && user.age >= 40); | |
return new Response(user?.email ?? "not found"); |
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
for await (let user of User.cursor()) { | |
if ((user.name === "Glauber Costa") && (user.age >= 40)) { | |
return new Response(user.email); | |
} | |
} | |
return new Response("not found"); |
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
const all = await User.findAll(); | |
const user = all.find(user => user.name == "Glauber Costa" && user.age >= 40); | |
return new Response(user?.email ?? "not found"); |
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
const users : User[] = [ | |
{ name: "Glauber Costa", email: "glauber@nospam.me", age: 40 }, | |
{ name: "Glauber Costa", email: "glauberjr@nospam.me", age: 15 }, | |
{ name: "Alvin Wisoky", email: "alwinjr@wisoky.me", age: 21 }, | |
{ name: "Alvin Wisoky", email: "alwin@wisoky.me", age: 41 }, | |
] | |
const user = users.find(user => user.name == "Glauber Costa" && user.age >= 40); | |
return new Response(user?.email ?? "not found"); |
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
class User { | |
name: string = ""; | |
email: string = ""; | |
age: number = 0; | |
} |
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
export function getSecret(key: string): JSONValue | undefined { | |
const secret = Deno.core.opSync("op_chisel_get_secret", key); | |
if (secret === undefined || secret === null) { | |
return undefined; | |
} | |
return secret; | |
} |
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
import { ChiselEntity } from "@chiselstrike/api" | |
export class Person extends ChiselEntity { | |
name: string; | |
age: number; | |
isHuman: boolean = false; | |
} |
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
await Person.findMany(p => p.age > 40); |