Change 'integerLength' in schema to 'dataLength'
This commit is contained in:
@@ -86,7 +86,7 @@ bun add github:moduletrace/bun-mariadb
|
||||
Connection settings are read from the environment (not the config file):
|
||||
|
||||
| Variable | Required | Description |
|
||||
| --------------------------------- | -------- | ------------------------------------ |
|
||||
| --------------------------------- | -------- | ---------------------------------- |
|
||||
| `BUN_MARIADB_SERVER_HOST` | Yes | MariaDB host |
|
||||
| `BUN_MARIADB_SERVER_USERNAME` | Yes | Database user |
|
||||
| `BUN_MARIADB_SERVER_PASSWORD` | Yes | Database password |
|
||||
@@ -135,9 +135,22 @@ const schema: BUN_MARIADB_DatabaseSchemaType = {
|
||||
{
|
||||
tableName: "users",
|
||||
fields: [
|
||||
{ fieldName: "first_name", dataType: "VARCHAR", integerLength: 255 },
|
||||
{ fieldName: "last_name", dataType: "VARCHAR", integerLength: 255 },
|
||||
{ fieldName: "email", dataType: "VARCHAR", integerLength: 255, unique: true },
|
||||
{
|
||||
fieldName: "first_name",
|
||||
dataType: "VARCHAR",
|
||||
dataLength: 255,
|
||||
},
|
||||
{
|
||||
fieldName: "last_name",
|
||||
dataType: "VARCHAR",
|
||||
dataLength: 255,
|
||||
},
|
||||
{
|
||||
fieldName: "email",
|
||||
dataType: "VARCHAR",
|
||||
dataLength: 255,
|
||||
unique: true,
|
||||
},
|
||||
{ fieldName: "bio", dataType: "LONGTEXT", html: true },
|
||||
],
|
||||
},
|
||||
@@ -188,7 +201,7 @@ await BunMariaDB.delete({ table: "users", targetId: 1 });
|
||||
The config file must be named `bun-mariadb.config.ts` and placed at the project root.
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------------------- | -------- | -------- | --------------------------------------------------------------------------- |
|
||||
| -------------------- | -------- | -------- | ----------------------------------------------------------------------------- |
|
||||
| `db_name` | `string` | Yes | MariaDB database name |
|
||||
| `db_dir` | `string` | Yes | Directory for schema, types, and local artifacts (relative to project root) |
|
||||
| `db_backup_dir` | `string` | No | Backup directory name, relative to `db_dir` (default: `.backups`) |
|
||||
@@ -197,7 +210,7 @@ The config file must be named `bun-mariadb.config.ts` and placed at the project
|
||||
| `typedef_file_path` | `string` | No | Output path for generated TypeScript types (relative to project root) |
|
||||
| `db_config` | `object` | No | Extra options passed to Bun's `SQL` MariaDB adapter |
|
||||
| `charset` | `string` | No | Database charset (default: `utf8mb4`) |
|
||||
| `connection_timeout`| `number` | No | Connection timeout in ms (default: `10000`) |
|
||||
| `connection_timeout` | `number` | No | Connection timeout in ms (default: `10000`) |
|
||||
| `ssl_ca` | `string` | No | Path to SSL CA certificate (relative to project root) |
|
||||
| `html_sanitize` | `object` | No | Extra HTML sanitizer allowlists (see [HTML Sanitization](#html-sanitization)) |
|
||||
|
||||
@@ -238,12 +251,38 @@ interface BUN_MARIADB_TableSchemaType {
|
||||
type BUN_MARIADB_FieldSchemaType = {
|
||||
fieldName?: string;
|
||||
dataType:
|
||||
| "CHAR" | "VARCHAR" | "TEXT" | "TINYTEXT" | "MEDIUMTEXT" | "LONGTEXT"
|
||||
| "TINYINT" | "SMALLINT" | "MEDIUMINT" | "INT" | "BIGINT"
|
||||
| "FLOAT" | "DOUBLE" | "DECIMAL"
|
||||
| "BINARY" | "VARBINARY" | "BLOB" | "TINYBLOB" | "MEDIUMBLOB" | "LONGBLOB"
|
||||
| "DATE" | "TIME" | "DATETIME" | "TIMESTAMP" | "YEAR"
|
||||
| "BOOLEAN" | "UUID" | "JSON" | "INET6" | "ENUM" | "SET" | "VECTOR";
|
||||
| "CHAR"
|
||||
| "VARCHAR"
|
||||
| "TEXT"
|
||||
| "TINYTEXT"
|
||||
| "MEDIUMTEXT"
|
||||
| "LONGTEXT"
|
||||
| "TINYINT"
|
||||
| "SMALLINT"
|
||||
| "MEDIUMINT"
|
||||
| "INT"
|
||||
| "BIGINT"
|
||||
| "FLOAT"
|
||||
| "DOUBLE"
|
||||
| "DECIMAL"
|
||||
| "BINARY"
|
||||
| "VARBINARY"
|
||||
| "BLOB"
|
||||
| "TINYBLOB"
|
||||
| "MEDIUMBLOB"
|
||||
| "LONGBLOB"
|
||||
| "DATE"
|
||||
| "TIME"
|
||||
| "DATETIME"
|
||||
| "TIMESTAMP"
|
||||
| "YEAR"
|
||||
| "BOOLEAN"
|
||||
| "UUID"
|
||||
| "JSON"
|
||||
| "INET6"
|
||||
| "ENUM"
|
||||
| "SET"
|
||||
| "VECTOR";
|
||||
primaryKey?: boolean;
|
||||
autoIncrement?: boolean;
|
||||
notNullValue?: boolean;
|
||||
@@ -253,7 +292,7 @@ type BUN_MARIADB_FieldSchemaType = {
|
||||
onUpdate?: string;
|
||||
onUpdateLiteral?: string;
|
||||
foreignKey?: BUN_MARIADB_ForeignKeyType;
|
||||
integerLength?: string | number; // e.g. VARCHAR length
|
||||
dataLength?: string | number; // e.g. VARCHAR length
|
||||
decimals?: string | number; // DECIMAL scale
|
||||
options?: (string | number)[]; // ENUM / SET values
|
||||
isVector?: boolean; // native VECTOR column
|
||||
@@ -369,7 +408,7 @@ bunx bun-mariadb export [options]
|
||||
```
|
||||
|
||||
| Option | Description |
|
||||
| ------------------- | --------------------------------------------------------------------------- |
|
||||
| ---------------- | -------------------------------------------------------------------------- |
|
||||
| `-o`, `--output` | Output archive path (`.tar.gz` or `.zip`). Defaults to `{db_dir}/.exports` |
|
||||
| `-f`, `--format` | When `--output` is omitted: `tar.gz` (default) or `zip` |
|
||||
|
||||
@@ -401,7 +440,7 @@ bunx bun-mariadb import [file] [options]
|
||||
```
|
||||
|
||||
| Option | Description |
|
||||
| ---------------- | --------------------------------------------------------------------------- |
|
||||
| --------------- | --------------------------------------------------------------------- |
|
||||
| `[file]` | Path to a `.sql` dump or export archive (`.tar.gz` / `.tar` / `.zip`) |
|
||||
| `--sql-only` | Archive only: restore SQL, do not overwrite `schema.ts` |
|
||||
| `--schema-only` | Archive only: write `schema.ts`, do not restore SQL |
|
||||
@@ -642,7 +681,7 @@ type ServerQueryParam<T> = {
|
||||
### Equality Operators
|
||||
|
||||
| Equality | SQL Equivalent |
|
||||
| ----------------------- | ------------------------------------------------------ |
|
||||
| ----------------------- | ----------------------------- |
|
||||
| `EQUAL` (default) | `=` |
|
||||
| `NOT EQUAL` | `!=` |
|
||||
| `LIKE` | `LIKE '%value%'` |
|
||||
@@ -715,7 +754,7 @@ MariaDB native `VECTOR(n)` columns and `VECTOR INDEX` are supported (MariaDB 11.
|
||||
{
|
||||
fieldName: "title",
|
||||
dataType: "VARCHAR",
|
||||
integerLength: 255,
|
||||
dataLength: 255,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
@@ -826,7 +865,7 @@ const res = await BunMariaDB.select<BUN_MARIADB_MY_APP_USERS>({
|
||||
Every table automatically receives:
|
||||
|
||||
| Field | Type | Description |
|
||||
| ------------ | ------------------------------- | -------------------------------------- |
|
||||
| ------------ | -------------------------------------------- | -------------------------------------- |
|
||||
| `id` | `BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL` | Unique row identifier |
|
||||
| `created_at` | `BIGINT` | Unix timestamp set on insert |
|
||||
| `updated_at` | `BIGINT` | Unix timestamp updated on every update |
|
||||
|
||||
Vendored
+14
-16
@@ -7,9 +7,9 @@ export default function mapDataType(field) {
|
||||
}
|
||||
switch (dataType) {
|
||||
case "CHAR":
|
||||
return `CHAR(${field.integerLength || 255})`;
|
||||
return `CHAR(${field.dataLength || 255})`;
|
||||
case "VARCHAR":
|
||||
return `VARCHAR(${field.integerLength || 255})`;
|
||||
return `VARCHAR(${field.dataLength || 255})`;
|
||||
case "TEXT":
|
||||
return "TEXT";
|
||||
case "TINYTEXT":
|
||||
@@ -19,36 +19,34 @@ export default function mapDataType(field) {
|
||||
case "LONGTEXT":
|
||||
return "LONGTEXT";
|
||||
case "TINYINT":
|
||||
return field.integerLength
|
||||
? `TINYINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `TINYINT(${field.dataLength})`
|
||||
: "TINYINT";
|
||||
case "SMALLINT":
|
||||
return field.integerLength
|
||||
? `SMALLINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `SMALLINT(${field.dataLength})`
|
||||
: "SMALLINT";
|
||||
case "MEDIUMINT":
|
||||
return field.integerLength
|
||||
? `MEDIUMINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `MEDIUMINT(${field.dataLength})`
|
||||
: "MEDIUMINT";
|
||||
case "INT":
|
||||
return field.integerLength ? `INT(${field.integerLength})` : "INT";
|
||||
return field.dataLength ? `INT(${field.dataLength})` : "INT";
|
||||
case "BIGINT":
|
||||
return field.integerLength
|
||||
? `BIGINT(${field.integerLength})`
|
||||
: "BIGINT";
|
||||
return field.dataLength ? `BIGINT(${field.dataLength})` : "BIGINT";
|
||||
case "FLOAT":
|
||||
return "FLOAT";
|
||||
case "DOUBLE":
|
||||
return "DOUBLE";
|
||||
case "DECIMAL":
|
||||
if (field.integerLength && field.decimals) {
|
||||
return `DECIMAL(${field.integerLength}, ${field.decimals})`;
|
||||
if (field.dataLength && field.decimals) {
|
||||
return `DECIMAL(${field.dataLength}, ${field.decimals})`;
|
||||
}
|
||||
return "DECIMAL(10,2)";
|
||||
case "BINARY":
|
||||
return `BINARY(${field.integerLength || 1})`;
|
||||
return `BINARY(${field.dataLength || 1})`;
|
||||
case "VARBINARY":
|
||||
return `VARBINARY(${field.integerLength || 255})`;
|
||||
return `VARBINARY(${field.dataLength || 255})`;
|
||||
case "BLOB":
|
||||
return "BLOB";
|
||||
case "TINYBLOB":
|
||||
|
||||
Vendored
+4
-1
@@ -213,7 +213,10 @@ export type BUN_MARIADB_FieldSchemaType = {
|
||||
onDelete?: string;
|
||||
onDeleteLiteral?: string;
|
||||
cssFiles?: string[];
|
||||
integerLength?: string | number;
|
||||
/**
|
||||
* Datatype length. Eg 255 for VARCHAR
|
||||
*/
|
||||
dataLength?: string | number;
|
||||
decimals?: string | number;
|
||||
code?: boolean;
|
||||
options?: (string | number)[];
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/bun-mariadb",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"description": "Schema-driven MariaDB manager for Bun",
|
||||
"author": "Benjamin Toby",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -13,9 +13,9 @@ export default function mapDataType(
|
||||
|
||||
switch (dataType) {
|
||||
case "CHAR":
|
||||
return `CHAR(${field.integerLength || 255})`;
|
||||
return `CHAR(${field.dataLength || 255})`;
|
||||
case "VARCHAR":
|
||||
return `VARCHAR(${field.integerLength || 255})`;
|
||||
return `VARCHAR(${field.dataLength || 255})`;
|
||||
case "TEXT":
|
||||
return "TEXT";
|
||||
case "TINYTEXT":
|
||||
@@ -25,36 +25,34 @@ export default function mapDataType(
|
||||
case "LONGTEXT":
|
||||
return "LONGTEXT";
|
||||
case "TINYINT":
|
||||
return field.integerLength
|
||||
? `TINYINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `TINYINT(${field.dataLength})`
|
||||
: "TINYINT";
|
||||
case "SMALLINT":
|
||||
return field.integerLength
|
||||
? `SMALLINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `SMALLINT(${field.dataLength})`
|
||||
: "SMALLINT";
|
||||
case "MEDIUMINT":
|
||||
return field.integerLength
|
||||
? `MEDIUMINT(${field.integerLength})`
|
||||
return field.dataLength
|
||||
? `MEDIUMINT(${field.dataLength})`
|
||||
: "MEDIUMINT";
|
||||
case "INT":
|
||||
return field.integerLength ? `INT(${field.integerLength})` : "INT";
|
||||
return field.dataLength ? `INT(${field.dataLength})` : "INT";
|
||||
case "BIGINT":
|
||||
return field.integerLength
|
||||
? `BIGINT(${field.integerLength})`
|
||||
: "BIGINT";
|
||||
return field.dataLength ? `BIGINT(${field.dataLength})` : "BIGINT";
|
||||
case "FLOAT":
|
||||
return "FLOAT";
|
||||
case "DOUBLE":
|
||||
return "DOUBLE";
|
||||
case "DECIMAL":
|
||||
if (field.integerLength && field.decimals) {
|
||||
return `DECIMAL(${field.integerLength}, ${field.decimals})`;
|
||||
if (field.dataLength && field.decimals) {
|
||||
return `DECIMAL(${field.dataLength}, ${field.decimals})`;
|
||||
}
|
||||
return "DECIMAL(10,2)";
|
||||
case "BINARY":
|
||||
return `BINARY(${field.integerLength || 1})`;
|
||||
return `BINARY(${field.dataLength || 1})`;
|
||||
case "VARBINARY":
|
||||
return `VARBINARY(${field.integerLength || 255})`;
|
||||
return `VARBINARY(${field.dataLength || 255})`;
|
||||
case "BLOB":
|
||||
return "BLOB";
|
||||
case "TINYBLOB":
|
||||
|
||||
+4
-1
@@ -202,7 +202,10 @@ export type BUN_MARIADB_FieldSchemaType = {
|
||||
onDelete?: string;
|
||||
onDeleteLiteral?: string;
|
||||
cssFiles?: string[];
|
||||
integerLength?: string | number;
|
||||
/**
|
||||
* Datatype length. Eg 255 for VARCHAR
|
||||
*/
|
||||
dataLength?: string | number;
|
||||
decimals?: string | number;
|
||||
code?: boolean;
|
||||
options?: (string | number)[];
|
||||
|
||||
Reference in New Issue
Block a user