Skip to main content

Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
•JSR Score100%•
License
Apache-2.0
•
Downloads292/wk
•
Publisheda day ago (0.0.10)

The database integration layer for NetScript: one provider-agnostic adapter contract plus Prisma v7 driver adapters for PostgreSQL, SQL Server, and MySQL, with connection-string helpers, JSON extensions, and OpenTelemetry tracing.

Examples

Basic Usage with Adapters

import { createPostgresAdapter } from '@netscript/database/adapters/postgres';
import { createMssqlAdapter } from '@netscript/database/adapters/mssql';
import { PrismaClient } from '@database';

declare const pgUrl: string;
declare const mssqlUrl: string;

// PostgreSQL
const pgAdapter = createPostgresAdapter({ connectionString: pgUrl });
const pgClient = new PrismaClient({ adapter: pgAdapter.getDriverAdapter() });

// SQL Server
const mssqlAdapter = createMssqlAdapter({ connectionString: mssqlUrl });
const mssqlClient = new PrismaClient({ adapter: mssqlAdapter.getDriverAdapter() });

Classes

c
PostgresAdapter<
TClient extends { $queryRaw: unknown; $queryRawUnsafe: unknown; $executeRaw: unknown; $executeRawUnsafe: unknown; $connect(): Promise<void>; $disconnect(): Promise<void>; }
>
(options: PostgresConnectionOptions)

PostgreSQL Adapter

  • connect(): Promise<void>

    Open the configured Prisma client connection.

  • disconnect(): Promise<void>

    Close the configured Prisma client connection.

  • executeRaw<T = unknown>(
    query: string,
    ...params: unknown[]
    ): Promise<T>

    Execute a raw query through the configured Prisma client.

  • executeRawUnsafe<T = unknown>(
    query: string,
    ...params: unknown[]
    ): Promise<T>

    Execute an unsafe raw command through the configured Prisma client.

  • getClient(): TClient

    Return the configured Prisma client instance.

  • getDriverAdapter(): PostgresDriverAdapter

    Get the Prisma driver adapter for use in client initialization

  • getStatus(): Promise<DatabaseConnectionStatus>

    Return a status snapshot for the current database connection.

  • healthCheck(): Promise<boolean>

    Probe the database connection with a lightweight query.

  • provider: "postgres"

    Database provider identity for status reporting.

  • setClient(client: TClient): void

    Set the Prisma client instance Call this after creating the PrismaClient with the driver adapter

Functions

f
buildMssqlConnectionString(parts: { host: string; port?: number; database: string; user?: string; password?: string; instanceName?: string; trustServerCertificate?: boolean; encrypt?: boolean; }): string

Build a SQL Server connection string from parts

f
buildPostgresConnectionString(parts: { host: string; port?: number; database: string; user?: string; password?: string; ssl?: boolean; }): string

Build a PostgreSQL connection string from parts

f
createPostgresAdapter<
TClient extends { $queryRaw: unknown; $queryRawUnsafe: unknown; $executeRaw: unknown; $executeRawUnsafe: unknown; $connect(): Promise<void>; $disconnect(): Promise<void>; }
>
(options: PostgresConnectionOptions): PostgresAdapter<TClient>

Create a PostgreSQL adapter

f

Enable Prisma OTEL instrumentation for database tracing

f
parseConnectionString(connectionString: string): { protocol: string; host: string; port: number; database: string; user?: string; password?: string; }

Parse a database connection string

f
registerJsonFields(
model: string,
fields: readonly string[]
): void

Register additional JSON fields for a model at runtime. Useful for plugin models that aren't known at compile time.

f
withTransaction<T, TTx>(
client: TransactionClientPort<TTx>,
fn: (tx: TTx) => Promise<T>,
options?: TransactionOptions
): Promise<T>

Execute operations within a transaction

Interfaces

I

Generic database adapter interface

  • connect(): Promise<void>

    Connect to the database Note: Prisma clients auto-connect on first query, but this can be used for explicit connection handling.

  • disconnect(): Promise<void>

    Disconnect from the database

  • executeRaw<T = unknown>(
    query: string,
    ...params: unknown[]
    ): Promise<T>

    Execute a raw SQL query

  • executeRawUnsafe<T = unknown>(
    query: string,
    ...params: unknown[]
    ): Promise<T>

    Execute a raw SQL query and return affected rows count

  • getClient(): TClient

    Get the underlying Prisma client

  • getStatus(): Promise<DatabaseConnectionStatus>

    Get connection status

  • healthCheck(): Promise<boolean>

    Check if the database is healthy

  • provider: DatabaseProvider

    Provider type

I

Factory for creating database adapters

  • create<TClient = unknown>(
    provider: DatabaseProvider,
    options: DatabaseConnectionOptions
    ): DatabaseAdapter<TClient>

    Create a database adapter for the given provider

I

Database connection options

I

Database connection status

  • connected: boolean

    Whether the connection is active

  • database: string

    Database name

  • error: string

    Error if connection failed

  • host: string

    Host/server name

  • Last successful connection timestamp

  • provider: DatabaseProvider

    Provider type

I

PostgreSQL-specific connection options

I

Public structural type returned by PostgreSQL driver adapter factories.

  • connect(): Promise<unknown>

    Open a Prisma driver connection.

  • connectToShadowDb(): Promise<unknown>

    Open a shadow database connection when supported by the driver.

  • provider: string

    Database provider identity.

I

Configuration for the shared database instance

I

Interactive provider boundary preserving the callback client's distinct type.

  • $transaction<TResult>(
    work: (tx: TTx) => Promise<TResult>,
    options?: TransactionOptions
    ): Promise<TResult>

    Invoke the callback once and resolve only after its physical commit or rollback.

I

Transaction options

  • isolationLevel: IsolationLevel

    Isolation level

  • maxWait: number

    Maximum time to wait for transaction to start

  • timeout: number

    Transaction timeout

Type Aliases

T
DatabaseProvider = "postgres" | "mssql" | "mysql" | "sqlite"

Database provider types

T
IsolationLevel =
"ReadUncommitted"
| "ReadCommitted"
| "RepeatableRead"
| "Serializable"
| "Snapshot"

Transaction isolation levels

Variables

v
jsonUtils: { readonly toJsonString: (value: unknown) => string | null; readonly fromJsonString: <T = unknown>(value: unknown) => T | null; readonly serializeData: (
model: string,
data: Record<string, unknown>
) => Record<string, unknown>
; readonly deserializeData: (
model: string,
data: Record<string, unknown>
) => Record<string, unknown>
; readonly getJsonFields: (model: string) => readonly string[]; readonly hasJsonFields: (model: string) => boolean; readonly resetRegistry: () => void; }

Export serialization utilities for manual use if needed. These are useful when working with raw queries or custom operations.

  • deserializeData: (
    model: string,
    data: Record<string, unknown>
    ) => Record<string, unknown>
    No documentation available
  • fromJsonString: <T = unknown>(value: unknown) => T | null
    No documentation available
  • getJsonFields: (model: string) => readonly string[]
    No documentation available
  • hasJsonFields: (model: string) => boolean
    No documentation available
  • resetRegistry: () => void
    No documentation available
  • serializeData: (
    model: string,
    data: Record<string, unknown>
    ) => Record<string, unknown>
    No documentation available
  • toJsonString: (value: unknown) => string | null
    No documentation available