MySQL adapter
The MySQL adapter introspects via information_schema and produces SQL with ? positional parameters and backtick-quoted identifiers.
Setup
import mysql from 'mysql2/promise';
import { Biref, mysqlAdapter } from '@biref/scanner';
const connection = await mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'secret',
database: 'mydb',
});
const biref = Biref.builder()
.withAdapter(mysqlAdapter.create(connection))
.build();
Client interface
mysqlAdapter.create() accepts any object matching this structural type:
interface MySQLClient {
execute<TRow>(
sql: string,
params?: any[],
): Promise<[TRow[], unknown]>;
}
Both mysql2/promise Connection and Pool satisfy this shape. The SDK never imports mysql2.
Namespace model
MySQL uses databases as namespaces. Default: the connected database (DATABASE()).
// Scan specific databases
const model = await biref.scan({ namespaces: ['mydb', 'other_db'] });
// Scan everything (excludes information_schema, mysql, performance_schema, sys)
const model = await biref.scan({ namespaces: 'all' });
// Default: scans the connected database
const model = await biref.scan();
URL schemes
mysql, mariadb
Type mapping
| MySQL type | Category |
|---|---|
| tinyint, smallint, mediumint, int, bigint | integer |
| tinyint(1) | boolean |
| decimal, numeric, float, double | decimal |
| varchar, char, text, tinytext, mediumtext, longtext | string |
| date, year | date |
| datetime, timestamp | timestamp |
| time | time |
| json | json |
| binary, varbinary, blob, tinyblob, mediumblob, longblob, bit | binary |
| enum | enum (values parsed from COLUMN_TYPE) |
| set | enum (values parsed from COLUMN_TYPE) |
tinyint(1) as boolean
MySQL conventionally uses TINYINT(1) for boolean columns. The adapter detects this via COLUMN_TYPE and maps it to the boolean category. Regular TINYINT (without the (1) display width) maps to integer.
Enum and set parsing
Enum values are extracted from the COLUMN_TYPE string:
enum('active','inactive','banned') -> ['active', 'inactive', 'banned']
set('read','write','admin') -> ['read', 'write', 'admin']
Record parser
MySQLRecordParser extends DefaultRecordParser with:
bigintstrings converted to JSbiginttinyint(1)numeric0/1converted to JSbooleanjsonstrings parsed to objectsdecimalpreserved as strings (driver default)
Indexes
Supports: btree, hash. Fulltext and spatial indexes map to unknown. MySQL does not support partial indexes.
Constraints
Supports: unique, check (MySQL 8.0.16+). Check constraints on older versions are silently skipped.
LIMIT / OFFSET
MySQL's prepared statement protocol does not reliably handle ? placeholders for LIMIT and OFFSET. The query engine inlines them as literal integers in the SQL text. They are safe since they always come from numeric values in the SDK, never from user input.