Skip to content

Commit

Permalink
split the loops
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Nov 26, 2024
1 parent ace67a0 commit 53d407f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
1 change: 0 additions & 1 deletion patches/exports/pglite
Original file line number Diff line number Diff line change
Expand Up @@ -6059,7 +6059,6 @@ _pg_hmac_init
_pg_hmac_update
_pg_inet_net_ntop
_pg_initdb
_pg_initdb_main
_pg_is_ascii
_pg_lsn_in
_pg_ltoa
Expand Down
58 changes: 51 additions & 7 deletions tests/repl.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
"pglite" : "./postgres.js",
"browser_wasi_shim" : "./browser_wasi_shim/dist/index.js",
"easywasi": "./easywasi.js",
"wip" : "/pygbag/wip.js",
"@zenfs/core": "https://esm.sh/@zenfs/core",
"@zenfs/dom": "https://esm.sh/@zenfs/dom",
"@zenfs/zip": "https://esm.sh/@zenfs/zip"
}
}
</script>
Expand All @@ -75,7 +71,56 @@
import initModule from "pglite";
window.initModule = initModule //(Module)

import "wip";
async function pglite_conf(vm, kv) {
var lines = vm.os.codec.decode(vm.FS.readFile(vm.PGDATA + "/postgresql.conf")).split('\n');

var buf = []
var newlines = [];

for (var k in kv)
{
var old = ""
for (var line = 0; line < lines.length; line++) {
if (lines[line].startsWith(k)) {
old = lines[line];
} else {
buf.push(lines[line])
}
}
var values = []
if (kv[k] instanceof Array) {
// TODO extract array of , from old
if (old.length) {
console.warn("// TODO extract array from old")
}
values = kv[k]
} else {
values.push(kv[k].toString())
}


const newline = `${k} = ${values.join(',')}\n`

if (!old.length) {
console.log("NEW :", newline)
} else {
if (old==newline)
console.log("no conf change :", newline)
else
console.error("EDIT :",old,'->', newline)
}
newlines.push(newline)
}
if (newlines.length) {
buf.push(...newlines)
vm.FS.writeFile( vm.PGDATA + "/postgresql.conf", buf.join("") )
vm.FS.syncfs(false, (e) => { if (e) console.error("pglite_conf error:", e)})
}
}

globalThis.pglite_conf = pglite_conf


#endif
</script>
</head>
Expand Down Expand Up @@ -884,7 +929,6 @@
console.log("---------------------")

import { WasiPreview1 } from 'easywasi'
//import { configure, InMemory, fs } from '@zenfs/core'

async function os_exec(bin, ...stack) {
var kw = {PWD: '/'}
Expand All @@ -909,7 +953,7 @@
const exe = `bin/${bin}.wasm`
console.log("Loading wasi bin : ", bin, "from", exe, "in", vm )

await os.FS.writeFile('/pg_dump', '\0', {mode:os.umask})
// await os.FS.writeFile('/pg_dump', '\0', {mode:os.umask})
// await os.FS.writeFile('/tmp/pglite/base/.s.PGSQL.5432.lock.in', '\0', {mode:os.umask})

os.PATH[bin] = await WebAssembly.instantiateStreaming(fetch(exe), {wasi_snapshot_preview1:wasi})
Expand Down

0 comments on commit 53d407f

Please sign in to comment.