MariaDB

Interface

import type { PoolConfig, QueryConfig } from "mariadb";
import type { SecureContextOptions } from "tls";

interface MariaDBDataSource extends DbDataSource {
    source: "mariadb";
    credential: string | MariaDBCredential;
    query?: string | QueryConfig;
    params?: unknown;
}

interface MariaDBCredential extends ServerAuth, PoolConfig {
    ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
}

Pool

import type { PoolConfig } from "mariadb";

interface PoolConfig {
    min?: number; // minimumIdle
    max?: number; // connectionLimit
    idle?: number; // idleTimeout
    queue_idle?: number; // acquireTimeout
    timeout?: number; // connectTimeout
    socket_timeout?: number; // socketTimeout
}

Authentication

{
  "dataSource": {
    "uri": "<username>:<password>@localhost:3306/<database>",
    /* OR */
    "credential": "main", // squared.db.json
    /* OR */
    "credential": {
      "host": "localhost", // Required
      "port": 3306,
      "user": "**********", // Required
      "password": "**********",
      "database": "example"
    },
    /* OR */
    "credential": {
      "socketPath": "/var/run/mysqld/mysql.sock",
      "user": "**********",
      "password": "**********",
      "database": "example"
    }
  }
}

Example usage

{
  "selector": "img",
  "type": "attribute",
  "dataSource": {
    "source": "mariadb",
    "credential": {/* Authentication */},

    "query": "SELECT * FROM table WHERE id = ? AND value = ?",
    "query": "./path/to/statement.sql", // Extension ".sql" (settings.directory.sql + users/username/?)
    "params": [1, "escaped"],
    /* OR */
    "query": { "namedPlaceholders": true, "sql": "SELECT * FROM table WHERE id = :id AND value = :value" },
    "params": { "id": 1, "value": "escaped" },

    /* Result: { "item_src": "mariadb.png", "item_alt": "MariaDB" } */
    "value": {
      "src": "item_src",
      "alt": "item_alt"
    },

    "usePool": true,
    "options": {
      "minimumIdle": 0,
      "connectionLimit": 10
    }
  }
}

@pi-r/mariadb

Added in version 0.6.2:

  • PoolConfig property queue_idle was implemented.