@netscript/prisma-adapter-mysql
Prisma driver adapter for MySQL and MariaDB on Deno. Use it when a Prisma client connects to MySQL
or MariaDB; it imports the npm mysql2/promise driver at runtime for connection pooling, query
execution and Node.js-compatible socket streams.
Sub-path exports
| Export | Entrypoint | Purpose |
|---|---|---|
@netscript/prisma-adapter-mysql |
./mod.ts |
The PrismaMySql factory, the connected adapter, and query, result and configuration types. |
PrismaMySql is the factory you construct with a connection configuration and pass to Prisma.
Prisma calls connect() and owns the resulting PrismaMySqlConnectedAdapter until $disconnect().
A direct connect() caller owns that result and must call dispose().
Adapter factory
| Symbol | Kind | Signature | Description |
|---|---|---|---|
PrismaMySql |
class | new PrismaMySql(config: MySqlConnectionConfig, options?: PrismaMySqlOptions) |
Factory for creating Prisma MySQL adapter instances. Exposes provider: "mysql", adapterName: string, and connect(): Promise<PrismaMySqlConnectedAdapter>. |
PrismaMySqlAdapterFactory |
class | PrismaMySqlAdapterFactory |
Re-export alias of PrismaMySql. |
inferCapabilities |
function | function inferCapabilities(version: unknown): MySqlCapabilities |
Infer server capabilities from a version string. |
Connected adapter
| Symbol | Kind | Description |
|---|---|---|
PrismaMySqlConnectedAdapter |
interface | Connected MySQL adapter returned by PrismaMySql.connect(). Provides queryRaw, executeRaw, executeScript, getConnectionInfo, startTransaction, dispose, and underlyingDriver. |
PrismaMySqlTransactionAdapter |
interface | Connected transaction adapter returned by startTransaction. Provides queryRaw, executeRaw, commit, and rollback. |
PrismaMySqlConnectionInfo |
interface | Connection details reported to Prisma (schemaName?, supportsRelationJoins). |
Query and result types
| Symbol | Kind | Description |
|---|---|---|
PrismaMySqlQuery |
interface | A Prisma query: sql: string, args: unknown[], and argTypes metadata for each argument. |
PrismaMySqlResultSet |
interface | Result set from raw queries: columnNames, columnTypes, rows, and optional lastInsertId. |
PrismaMySqlIsolationLevel |
type alias | "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SNAPSHOT" | "SERIALIZABLE" — isolation levels accepted by the adapter. |
Configuration types
| Symbol | Kind | Description |
|---|---|---|
MySqlConnectionConfig |
interface | Structured MySQL connection configuration: hostname?, port?, username?, password?, db?, poolSize?, timeout?, and tls?. |
PrismaMySqlOptions |
interface | Adapter options: database? (reported schema name) and onConnectionError? (contained connection-failure observer). |
MySqlCapabilities |
interface | Capabilities of the connected MySQL server (supportsRelationJoins). |
Runtime and deployment constraints
- Dependency: imports
mysql2/promisefrom npm at runtime. - Node compatibility: the deployment must provide Deno npm resolution and Node-compatible
socket APIs; database access requires
--allow-net. - Pool ownership: pass the
PrismaMySqlfactory to Prisma. Prisma owns the connectedmysql2pool and closes it through$disconnect(). Only callers that invokeconnect()directly own the returned adapter and calldispose()themselves. - Timeout:
timeoutmaps only to mysql2connectTimeout, the initial connection-establishment deadline. It is not a query, transaction, queue, idle, or total-operation timeout; mysql2 supplies its default when omitted. - Connection strings: this low-level factory accepts only the individual
MySqlConnectionConfigfields. Higher-level NetScript database configuration may normalize other input forms separately.
Legacy TLS mode
tls.mode: "verify_identity" is deprecated because its name does not match its legacy behavior.
Examples
Connect Prisma Client to MySQL
import { PrismaClient } from "../../schema/.generated/client.server.ts";
import { PrismaMySql } from "@netscript/prisma-adapter-mysql";
// 1. Connection configuration
const config = {
hostname: "localhost",
port: 3306,
username: "root",
password: "password",
db: "mydb",
poolSize: 5,
timeout: 10000,
};
// 2. Construct the adapter factory with options
const adapterFactory = new PrismaMySql(config, {
database: "mydb",
onConnectionError(error) {
console.error("MySQL connection error:", error);
},
});
// 3. Pass the factory to Prisma Client; Prisma opens the pool on connect.
const prisma = new PrismaClient({ adapter: adapterFactory });
try {
// 4. Run a query
const result = await prisma.$queryRawUnsafe("SELECT 1 + 1");
console.log("Query Result:", result);
} finally {
// 5. Deterministically disconnect Prisma and close its connection pool.
await prisma.$disconnect();
}
The literal host and port are for illustration. In a NetScript workspace, Aspire assigns the
database endpoint, and @netscript/database/adapters/mysql reads it from the environment
(getMysqlConfigFromEnv).