import a from"node:path";import{sql as o}from"drizzle-orm";import{drizzle as c}from"drizzle-orm/libsql";import{migrate as l}from"drizzle-orm/libsql/migrator";import{TransactionsManager as m}from"./transactions-manager.js";class e{dbClient;#t;constructor(t,i){this.dbClient=c(i(t)),this.#t=new m(this.dbClient)}get transactionsManager(){return this.#t}get client(){return this.#t.tx??this.dbClient}static async init(t,i){const{createClient:s}=await import("@libsql/client"),r=new e(t,s);return i?.runWithPragmaWalWriteOptimization&&await r.dbClient.run(o.raw("PRAGMA journal_mode = WAL;")),r}async migrate(t,i=""){await l(this.dbClient,{migrationsFolder:a.join(t,"migrations",i)})}async close(){this.dbClient.$client.close()}async sync(){try{await this.dbClient.$client.sync()}catch(t){if(d(t))return;throw t}}}function d(n){if(!(n instanceof Error))return!1;const t=n.message.toLowerCase();return t.includes("syncnotsupported")&&(t.includes('("file")')||t.includes('"file"'))}export{e as DatabaseClient};
