rename files

This commit is contained in:
polv committed 2020-12-15 16:27:52 +07:00
1 parent 1fdaf73f14
commit 31dd2b0049
72 files changed
+10320 -31

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import sqlite3 from 'better-sqlite3'
export interface IPost {
slug: string
date?: Date
title: string
image?: string
tag?: string[]
/**
* cleaned markdown
*/
content: string
excerptHtml: string
contentHtml: string
}
export class Database {
db: sqlite3.Database
constructor(public filepath: string) {
this.db = sqlite3(filepath)
}
public init(): void {
this.db.exec(/* sql */ `
CREATE VIRTUAL TABLE q USING fts5 (
slug,
[date] UNINDEXED, -- epoch milli
title,
[image] UNINDEXED,
tag, -- space separated
content, -- cleaned markdown
excerptHtml UNINDEXED,
contentHtml UNINDEXED
);
`)
}
public insert(...ps: IPost[]): void {
const stmt = this.db.prepare(/* sql */ `
INSERT INTO q (slug, [date], title, [image], tag, content, excerptHtml, contentHtml)
VALUES (@slug, @date, @title, @image, @tag, @content, @excerptHtml, @contentHtml)
`)
this.db.transaction(() => {
// eslint-disable-next-line array-callback-return
ps.map((p) => {
stmt.run({
...p,
date: p.date ? p.date.getTime() : undefined,
tag: (p.tag || []).join(' '),
})
})
})()
}
}