Skip to content

Commit 570722e

Browse files
committed
json.stringify
1 parent b0f1a19 commit 570722e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/cloudflare/src/api/d1-tag-cache.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class D1TagCache implements TagCache {
3030

3131
try {
3232
const { success, results } = await db
33-
.prepare(`SELECT tag FROM ${table.tags} WHERE path = ?`)
33+
.prepare(`SELECT tag FROM ${JSON.stringify(table.tags)} WHERE path = ?`)
3434
.bind(path)
3535
.all<{ tag: string }>();
3636

@@ -54,7 +54,7 @@ class D1TagCache implements TagCache {
5454

5555
try {
5656
const { success, results } = await db
57-
.prepare(`SELECT path FROM ${table.tags} WHERE tag = ?`)
57+
.prepare(`SELECT path FROM ${JSON.stringify(table.tags)} WHERE tag = ?`)
5858
.bind(tag)
5959
.all<{ path: string }>();
6060

@@ -77,9 +77,9 @@ class D1TagCache implements TagCache {
7777
try {
7878
const { success, results } = await db
7979
.prepare(
80-
`SELECT ${table.revalidations}.tag FROM ${table.revalidations}
81-
INNER JOIN ${table.tags} ON ${table.revalidations}.tag = ${table.tags}.tag
82-
WHERE ${table.tags}.path = ? AND ${table.revalidations}.revalidatedAt > ?;`
80+
`SELECT ${JSON.stringify(table.revalidations)}.tag FROM ${JSON.stringify(table.revalidations)}
81+
INNER JOIN ${JSON.stringify(table.tags)} ON ${JSON.stringify(table.revalidations)}.tag = ${JSON.stringify(table.tags)}.tag
82+
WHERE ${JSON.stringify(table.tags)}.path = ? AND ${JSON.stringify(table.revalidations)}.revalidatedAt > ?;`
8383
)
8484
.bind(this.getCacheKey(path), lastModified ?? 0)
8585
.all<{ tag: string }>();
@@ -104,13 +104,13 @@ class D1TagCache implements TagCache {
104104
if (revalidatedAt === 1) {
105105
// new tag/path mapping from set
106106
return db
107-
.prepare(`INSERT INTO ${table.tags} (tag, path) VALUES (?, ?)`)
107+
.prepare(`INSERT INTO ${JSON.stringify(table.tags)} (tag, path) VALUES (?, ?)`)
108108
.bind(this.getCacheKey(tag), this.getCacheKey(path));
109109
}
110110

111111
// tag was revalidated
112112
return db
113-
.prepare(`INSERT INTO ${table.revalidations} (tag, revalidatedAt) VALUES (?, ?)`)
113+
.prepare(`INSERT INTO ${JSON.stringify(table.revalidations)} (tag, revalidatedAt) VALUES (?, ?)`)
114114
.bind(this.getCacheKey(tag), revalidatedAt ?? Date.now());
115115
})
116116
);

packages/cloudflare/src/cli/build/open-next/compile-cache-assets-manifest.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function compileCacheAssetsManifestSqlFile(options: BuildOptions) {
2323
mkdirSync(path.dirname(outputPath), { recursive: true });
2424
writeFileSync(
2525
outputPath,
26-
`CREATE TABLE IF NOT EXISTS ${tagsTable} (tag TEXT NOT NULL, path TEXT NOT NULL, UNIQUE(tag, path) ON CONFLICT REPLACE);
27-
CREATE TABLE IF NOT EXISTS ${revalidationsTable} (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);\n`
26+
`CREATE TABLE IF NOT EXISTS ${JSON.stringify(tagsTable)} (tag TEXT NOT NULL, path TEXT NOT NULL, UNIQUE(tag, path) ON CONFLICT REPLACE);
27+
CREATE TABLE IF NOT EXISTS ${JSON.stringify(revalidationsTable)} (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);\n`
2828
);
2929

3030
if (existsSync(rawManifestPath)) {
@@ -35,7 +35,10 @@ export function compileCacheAssetsManifestSqlFile(options: BuildOptions) {
3535
);
3636

3737
if (values.length) {
38-
appendFileSync(outputPath, `INSERT INTO ${tagsTable} (tag, path) VALUES ${values.join(", ")};`);
38+
appendFileSync(
39+
outputPath,
40+
`INSERT INTO ${JSON.stringify(tagsTable)} (tag, path) VALUES ${values.join(", ")};`
41+
);
3942
}
4043
}
4144
}

0 commit comments

Comments
 (0)