-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
7 additions
and
21 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
DEFINE EVENT post_read_time ON TABLE post WHEN $event = "UPDATE" && $before.body != $after.body THEN { | ||
DEFINE EVENT post_read_time ON TABLE post WHEN ($event = "UPDATE" || $event = "CREATE") && $before.body != $after.body THEN { | ||
LET $read_time = array::len(string::words($after.body)) / 200; | ||
UPDATE post SET read_time = math::round($read_time) WHERE id = $after.id; | ||
UPDATE post SET read_time = math::max([1, $read_time]) WHERE id = $after.id; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
{"schemas":"DEFINE TABLE author TYPE NORMAL SCHEMAFULL\n PERMISSIONS \n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD id ON author TYPE record<author> ASSERT $value != NONE;\nDEFINE FIELD name ON author TYPE string ASSERT $value != NONE;\nDEFINE FIELD bio ON author TYPE option<string>;\nDEFINE FIELD email ON author TYPE string ASSERT string::is::email($value);\nDEFINE FIELD linkedin ON author TYPE option<string>;\nDEFINE FIELD twitter ON author TYPE option<string>;\nDEFINE FIELD github ON author TYPE option<string>;\n\nDEFINE TABLE post TYPE NORMAL SCHEMAFULL \n PERMISSIONS \n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD id ON post TYPE record<post> ASSERT $value != NONE;\nDEFINE FIELD title ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD summary ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD body ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD slug ON post TYPE option<string>;\nDEFINE FIELD tags ON post TYPE array<string> ASSERT $value != NONE;\nDEFINE FIELD author ON post TYPE record<author> ASSERT $value != NONE;\nDEFINE FIELD read_time ON post TYPE int ASSERT $value != NONE;\nDEFINE FIELD total_views ON post TYPE int DEFAULT 0;\nDEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();\nDEFINE FIELD updated_at ON post TYPE datetime VALUE time::now();\nDEFINE TABLE script_migration SCHEMAFULL\n PERMISSIONS\n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD script_name ON script_migration TYPE string;\nDEFINE FIELD executed_at ON script_migration TYPE datetime VALUE time::now() READONLY;","events":"DEFINE EVENT post_read_time ON TABLE post WHEN $event = \"UPDATE\" && $before.body != $after.body THEN {\n LET $read_time = array::len(string::words($after.body)) / 200;\n UPDATE post SET read_time = math::round($read_time) WHERE id = $after.id;\n};\n\nDEFINE EVENT post_slug ON TABLE post WHEN ($event = \"CREATE\" OR $event = \"UPDATE\") && $before.title != $after.title THEN (\n UPDATE post SET slug = string::slug($after.title) WHERE id = $after.id\n);\n"} | ||
{ | ||
"schemas": "DEFINE TABLE author TYPE NORMAL SCHEMAFULL\n PERMISSIONS \n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD id ON author TYPE record<author> ASSERT $value != NONE;\nDEFINE FIELD name ON author TYPE string ASSERT $value != NONE;\nDEFINE FIELD bio ON author TYPE option<string>;\nDEFINE FIELD email ON author TYPE string ASSERT string::is::email($value);\nDEFINE FIELD linkedin ON author TYPE option<string>;\nDEFINE FIELD twitter ON author TYPE option<string>;\nDEFINE FIELD github ON author TYPE option<string>;\n\nDEFINE TABLE post TYPE NORMAL SCHEMAFULL \n PERMISSIONS \n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD id ON post TYPE record<post> ASSERT $value != NONE;\nDEFINE FIELD title ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD summary ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD body ON post TYPE string ASSERT $value != NONE;\nDEFINE FIELD slug ON post TYPE option<string>;\nDEFINE FIELD tags ON post TYPE array<string> ASSERT $value != NONE;\nDEFINE FIELD author ON post TYPE record<author> ASSERT $value != NONE;\nDEFINE FIELD read_time ON post TYPE int ASSERT $value != NONE;\nDEFINE FIELD total_views ON post TYPE int DEFAULT 0;\nDEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();\nDEFINE FIELD updated_at ON post TYPE datetime VALUE time::now();\nDEFINE TABLE script_migration SCHEMAFULL\n PERMISSIONS\n FOR select FULL\n FOR create, update, delete NONE;\n\nDEFINE FIELD script_name ON script_migration TYPE string;\nDEFINE FIELD executed_at ON script_migration TYPE datetime VALUE time::now() READONLY;", | ||
"events": "DEFINE EVENT post_read_time ON TABLE post WHEN $event = \"UPDATE\" && $before.body != $after.body THEN {\n LET $read_time = array::len(string::words($after.body)) / 200;\n UPDATE post SET read_time = math::round($read_time) WHERE id = $after.id;\n};\n\nDEFINE EVENT post_slug ON TABLE post WHEN ($event = \"CREATE\" OR $event = \"UPDATE\") && $before.title != $after.title THEN (\n UPDATE post SET slug = string::slug($after.title) WHERE id = $after.id\n);\n" | ||
} |
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