1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-11-05 04:15:41 -05:00

bump next

This commit is contained in:
2022-04-12 20:01:34 -04:00
parent 8641b6a90e
commit 1648464e0e
4 changed files with 191 additions and 171 deletions

View File

@@ -24,45 +24,43 @@ const {
ToInteger,
} = faunadb.query;
export default function run() {
// initializes the empty database
CreateCollection({ name: "hits" });
// initializes the empty database
CreateCollection({ name: "hits" });
// this allows us to quickly pull a post's corresponding row
CreateIndex({
name: "hits_by_slug",
source: Collection("hits"),
terms: [
{
field: ["data", "slug"],
},
],
unique: false,
serialized: true,
});
// this allows us to quickly pull a post's corresponding row
CreateIndex({
name: "hits_by_slug",
source: Collection("hits"),
terms: [
{
field: ["data", "slug"],
},
],
unique: false,
serialized: true,
});
// a wrapper to get a post's row, add one to it, and return the new tally
CreateFunction({
name: "increment_hit",
body: Query(
Lambda(
"slug",
Let(
{ match: Match(Index("hits_by_slug"), Var("slug")) },
If(
Exists(Var("match")),
Let(
{
ref: Select("ref", Get(Var("match"))),
hits: ToInteger(Select("hits", Select("data", Get(Var("match"))))),
},
Update(Var("ref"), { data: { hits: Add(Var("hits"), 1) } })
),
Create(Collection("hits"), { data: { slug: Var("slug"), hits: 1 } })
)
// a wrapper to get a post's row, add one to it, and return the new tally
CreateFunction({
name: "increment_hit",
body: Query(
Lambda(
"slug",
Let(
{ match: Match(Index("hits_by_slug"), Var("slug")) },
If(
Exists(Var("match")),
Let(
{
ref: Select("ref", Get(Var("match"))),
hits: ToInteger(Select("hits", Select("data", Get(Var("match"))))),
},
Update(Var("ref"), { data: { hits: Add(Var("hits"), 1) } })
),
Create(Collection("hits"), { data: { slug: Var("slug"), hits: 1 } })
)
)
),
role: Role("server"),
});
}
)
),
role: Role("server"),
});