Files
turso/bindings/javascript/packages/browser/promise-default.ts
Nikita Sivukhin 974feac27b move compute to the main thread for browser and node
- now, most of the work is happening on the main thread
- for database in browser, we still have dedicated WebWorker - but it is used only for OPFS access and only for that
- for syn in browser we still offload sync operations to the WebWorker
2025-09-19 13:19:30 +04:00

29 lines
926 B
TypeScript

import { DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
import { Database, connect as promiseConnect } from "./promise.js";
import { initThreadPool, MainWorker, connectDbAsync } from "./index-default.js";
/**
* Creates a new database connection asynchronously.
*
* @param {string} path - Path to the database file.
* @param {Object} opts - Options for database behavior.
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
*/
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
const init = async () => {
await initThreadPool();
if (MainWorker == null) {
throw new Error("panic: MainWorker is not initialized");
}
return MainWorker;
};
return await promiseConnect(
path,
opts,
connectDbAsync,
init
);
}
export { connect, Database, SqliteError }