MCPcopy
hub / github.com/BuilderIO/agent-native / getDialect

Function getDialect

packages/core/src/db/client.ts:173–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

171let _dialect: Dialect | undefined;
172
173export function getDialect(): Dialect {
174 if (_dialect !== undefined) return _dialect;
175
176 // DATABASE_URL takes priority over D1 when set.
177 const url = getDatabaseUrl();
178 if (url.startsWith("postgres://") || url.startsWith("postgresql://")) {
179 _dialect = "postgres";
180 return _dialect;
181 }
182 if (url && !url.startsWith("file:")) {
183 // Remote libsql (e.g. Turso)
184 _dialect = "sqlite";
185 return _dialect;
186 }
187
188 const d1 = globalThis.__cf_env?.DB;
189 if (d1) {
190 _dialect = "d1";
191 return _dialect;
192 }
193
194 // Don't cache the fallthrough — on CF Workers, env bindings (__cf_env) aren't
195 // available at import time. If we cache "sqlite" here, D1 will never be
196 // detected once the bindings are set in the fetch handler.
197 return "sqlite";
198}
199
200export function isPostgres(): boolean {
201 return getDialect() === "postgres";

Callers 8

createBetterAuthInstanceFunction · 0.85
runMigrationsFunction · 0.85
isPostgresFunction · 0.85
isLocalDatabaseFunction · 0.85
initClientFunction · 0.85
pgFunction · 0.85
startInitFunction · 0.85
client.spec.tsFile · 0.85

Calls 1

getDatabaseUrlFunction · 0.85

Tested by

no test coverage detected