This commit is contained in:
Leandro Facchinetti 2021-03-12 14:42:53 +00:00
parent 4383a72ecb
commit c954814fc4
1 changed files with 8 additions and 8 deletions

View File

@ -28,18 +28,18 @@ export default function killTheNewsletter(
const database = new Database( const database = new Database(
path.join(rootDirectory, "kill-the-newsletter.db") path.join(rootDirectory, "kill-the-newsletter.db")
); );
database.function("newReference", (): string => database.function("newRandomReference", (): string =>
cryptoRandomString({ cryptoRandomString({
length: 16, length: 16,
characters: "abcdefghijklmnopqrstuvwxyz0123456789", characters: "abcdefghijklmnopqrstuvwxyz0123456789",
}) })
); );
database.function( database.function(
"entryFeedCreatedTitle", "welcomeEntryTitle",
(title: string): string => `${title}” inbox created` (title: string): string => `${title}” inbox created`
); );
database.function( database.function(
"entryFeedCreatedContent", "welcomeEntryContent",
(feedReference: string): HTML => html` (feedReference: string): HTML => html`
<p> <p>
Sign up for the newsletter with<br /> Sign up for the newsletter with<br />
@ -72,29 +72,29 @@ export default function killTheNewsletter(
"id" INTEGER PRIMARY KEY AUTOINCREMENT, "id" INTEGER PRIMARY KEY AUTOINCREMENT,
"createdAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "createdAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
"reference" TEXT NOT NULL UNIQUE DEFAULT (newReference()), "reference" TEXT NOT NULL UNIQUE DEFAULT (newRandomReference()),
"title" TEXT NOT NULL "title" TEXT NOT NULL
); );
CREATE TABLE "entries" ( CREATE TABLE "entries" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT, "id" INTEGER PRIMARY KEY AUTOINCREMENT,
"createdAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "createdAt" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
"reference" TEXT NOT NULL UNIQUE DEFAULT (newReference()), "reference" TEXT NOT NULL UNIQUE DEFAULT (newRandomReference()),
"feed" INTEGER NOT NULL REFERENCES "feeds", "feed" INTEGER NOT NULL REFERENCES "feeds",
"title" TEXT NOT NULL, "title" TEXT NOT NULL,
"author" TEXT NOT NULL, "author" TEXT NOT NULL,
"content" TEXT NOT NULL "content" TEXT NOT NULL
); );
CREATE TRIGGER "entryFeedCreated" CREATE TRIGGER "welcomeEntry"
AFTER INSERT ON "feeds" AFTER INSERT ON "feeds"
BEGIN BEGIN
INSERT INTO "entries" ("feed", "title", "author", "content") INSERT INTO "entries" ("feed", "title", "author", "content")
VALUES ( VALUES (
"NEW"."id", "NEW"."id",
entryFeedCreatedTitle("NEW"."title"), welcomeEntryTitle("NEW"."title"),
'Kill the Newsletter!', 'Kill the Newsletter!',
entryFeedCreatedContent("NEW"."reference") welcomeEntryContent("NEW"."reference")
); );
END; END;