Timo
Explore posts from serversdeno include and cannot execute file when compiled
async function run() {
const o = await Deno.readFile(`${import.meta.dirname}/win_clipboard.exe`);
console.log(o); // <-- Works and outputs the buffer
const command = new Deno.Command(`${import.meta.dirname}/win_clipboard.exe`, {
args: ["--read"],
stdin: "piped",
stdout: "piped",
}).spawn(); // <-- Fails here
const output = await command.output();
return output;
}
async function run() {
const o = await Deno.readFile(`${import.meta.dirname}/win_clipboard.exe`);
console.log(o); // <-- Works and outputs the buffer
const command = new Deno.Command(`${import.meta.dirname}/win_clipboard.exe`, {
args: ["--read"],
stdin: "piped",
stdout: "piped",
}).spawn(); // <-- Fails here
const output = await command.output();
return output;
}
deno compile -A --include ./win_clipboard.exe --target x86_64-pc-windows-msvc index.ts
deno compile -A --include ./win_clipboard.exe --target x86_64-pc-windows-msvc index.ts
Uint8Array(6656) [
77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0,
255, 255, 0, 0, 184, 0, 0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 14, 31, 186, 14, 0, 180, 9, 205,
33, 184, 1, 76, 205, 33, 84, 104, 105, 115, 32, 112,
114, 111, 103, 114, 97, 109, 32, 99, 97, 110, 110, 111,
116, 32, 98, 101,
... 6556 more items
]
ABC: error: Uncaught (in promise) NotFound: Failed to spawn 'C:\Users\ADMINI~1\AppData\Local\Temp\2\deno-compile-ClipboardShare-App.exe\ClipboardShare-App\win_clipboard.exe': Das System kann den angegebenen Pfad nicht finden. (os error 3): Das System kann den angegebenen Pfad nicht finden. (os error 3): Das System kann den angegebenen Pfad nicht finden. (os error 3)
at spawnChildInner (ext:runtime/40_process.js:184:17)
at spawnChild (ext:runtime/40_process.js:208:10)
at Command.spawn (ext:runtime/40_process.js:483:12)
at run (file:///C:/Users/ADMINI~1/AppData/Local/Temp/2/deno-compile-ClipboardShare-App.exe/ClipboardShare-App/index.ts:55:6)
at eventLoopTick (ext:core/01_core.js:175:7)
at async main (file:///C:/Users/ADMINI~1/AppData/Local/Temp/2/deno-compile-ClipboardShare-App.exe/ClipboardShare-App/index.ts:71:18)
Uint8Array(6656) [
77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0,
255, 255, 0, 0, 184, 0, 0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 14, 31, 186, 14, 0, 180, 9, 205,
33, 184, 1, 76, 205, 33, 84, 104, 105, 115, 32, 112,
114, 111, 103, 114, 97, 109, 32, 99, 97, 110, 110, 111,
116, 32, 98, 101,
... 6556 more items
]
ABC: error: Uncaught (in promise) NotFound: Failed to spawn 'C:\Users\ADMINI~1\AppData\Local\Temp\2\deno-compile-ClipboardShare-App.exe\ClipboardShare-App\win_clipboard.exe': Das System kann den angegebenen Pfad nicht finden. (os error 3): Das System kann den angegebenen Pfad nicht finden. (os error 3): Das System kann den angegebenen Pfad nicht finden. (os error 3)
at spawnChildInner (ext:runtime/40_process.js:184:17)
at spawnChild (ext:runtime/40_process.js:208:10)
at Command.spawn (ext:runtime/40_process.js:483:12)
at run (file:///C:/Users/ADMINI~1/AppData/Local/Temp/2/deno-compile-ClipboardShare-App.exe/ClipboardShare-App/index.ts:55:6)
at eventLoopTick (ext:core/01_core.js:175:7)
at async main (file:///C:/Users/ADMINI~1/AppData/Local/Temp/2/deno-compile-ClipboardShare-App.exe/ClipboardShare-App/index.ts:71:18)
6 replies
DTDrizzle Team
•Created by Timo on 6/6/2024 in #help
Auto reconnect to database
Hello,
I am trying to auto reconnect to my PostgreSQL database.
What is the best practice?
But I have some issues with it.
I use SvelteKit.
This is my current code:
import 'dotenv/config';
import * as schema from './schema';
import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
import pg from "pg";
let isConnected = false;
let connecting = false;
let db: NodePgDatabase<typeof schema>;
const createClient = () => {
return new pg.Client({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 5000,
statement_timeout: 5000,
query_timeout: 5000,
});
};
const connect = async () => {
if (connecting) return;
connecting = true;
const client = createClient();
client.on('error', (error) => {
isConnected = false;
console.log("[PostgreSQL] Connection Error", error);
if (!connecting) {
setTimeout(connect, 5000);
}
});
console.log("[PostgreSQL] Connecting to Database");
try {
await client.connect();
isConnected = true;
console.log("[PostgreSQL] Connected to Database");
db = drizzle(client, { schema });
} catch (error) {
isConnected = false;
console.log("[PostgreSQL] Connection Error", error);
setTimeout(connect, 5000);
} finally {
connecting = false;
}
};
await connect();
export { db, isConnected };
import 'dotenv/config';
import * as schema from './schema';
import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
import pg from "pg";
let isConnected = false;
let connecting = false;
let db: NodePgDatabase<typeof schema>;
const createClient = () => {
return new pg.Client({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 5000,
statement_timeout: 5000,
query_timeout: 5000,
});
};
const connect = async () => {
if (connecting) return;
connecting = true;
const client = createClient();
client.on('error', (error) => {
isConnected = false;
console.log("[PostgreSQL] Connection Error", error);
if (!connecting) {
setTimeout(connect, 5000);
}
});
console.log("[PostgreSQL] Connecting to Database");
try {
await client.connect();
isConnected = true;
console.log("[PostgreSQL] Connected to Database");
db = drizzle(client, { schema });
} catch (error) {
isConnected = false;
console.log("[PostgreSQL] Connection Error", error);
setTimeout(connect, 5000);
} finally {
connecting = false;
}
};
await connect();
export { db, isConnected };
1 replies