Skip to content

Commit

Permalink
fix: the init fn will be called again whenever a new bundle is deploy…
Browse files Browse the repository at this point in the history
…ed, by checking a "bundle id"
  • Loading branch information
ferm10n committed Jul 29, 2024
1 parent 3201e69 commit 55f258b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/impl/PLV8ifyCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type FnSqlConfig = {
export class PLV8ifyCLI implements PLV8ify {
private _bundler: Bundler
private _tsCompiler: TSCompiler
private bundleId = Date.now()

private _typeMap: Record<string, string> = {
number: 'float8',
Expand Down Expand Up @@ -179,7 +180,7 @@ export class PLV8ifyCLI implements PLV8ify {
}

// set a global symbol so that we can check if the init function has been called
bundledJs += `globalThis[Symbol.for('${scopePrefix}_initialized')] = true;\n`
bundledJs += `globalThis[Symbol.for('${scopePrefix}_initialized')] = ${this.bundleId};\n`
}

const initFunction = this.getPLV8SQLFunction({
Expand Down Expand Up @@ -307,7 +308,7 @@ export class PLV8ifyCLI implements PLV8ify {
.with(
'bundle',
() =>
`if (!globalThis[Symbol.for('${scopePrefix}_initialized')]) plv8.execute('SELECT ${scopePrefix}_init();');`
`if (globalThis[Symbol.for('${scopePrefix}_initialized')] !== ${this.bundleId}) plv8.execute('SELECT ${scopePrefix}_init();');`
)
.otherwise(() => ''),
match(sqlReturnType.toLowerCase())
Expand Down

0 comments on commit 55f258b

Please sign in to comment.