rename files
This commit is contained in:
1 parent
1fdaf73f14
commit
31dd2b0049
72 files changed
+10320
-31
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# ASSETS
|
||||
|
||||
**This directory is not required, you can delete it if you don't want to use it.**
|
||||
|
||||
This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
|
||||
|
||||
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
|
||||
@@ -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(' '),
|
||||
})
|
||||
})
|
||||
})()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user