Registry / database / mysql-admin-sql-gen

mysql-admin-sql-gen

JSON →
library0.1.1jsnpmunverified

A library for generating MySQL administrative SQL statements such as CREATE DATABASE, CREATE ROLE, CREATE USER, and GRANT. Version 0.1.1 is the only release; no further updates have been made. It is similar to Squel but for DDL/DCL statements. Unlike ORMs that expect roles/users/databases to exist already, this library provides an API to generate these statements programmatically, with proper escaping and support for browser environments.

npm install mysql-admin-sql-gen
INSTALL
IMPORT
SIG · MYSQL-ADMIN-SQL-GE
M
mysql-admin-sql-gen
databasejavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createDatabase
import { createDatabase } from 'mysql-admin-sql-gen'
const { createDatabase } = require('mysql-admin-sql-gen')
If using Node <7.10.1, you may need a transpiler or use dynamic import.
createUser
import { createUser } from 'mysql-admin-sql-gen'
import createUser from 'mysql-admin-sql-gen'
This is a named export, not a default export.
grant
import { grant } from 'mysql-admin-sql-gen'
const grant = require('mysql-admin-sql-gen').grant;
CommonJS require is not officially supported; use ES modules.

Shows how to generate CREATE DATABASE, CREATE USER, and GRANT SQL statements using the library.

import { createDatabase, createUser, grant } from 'mysql-admin-sql-gen'; const dbConfig = { database: 'example', users: { readonly: { name: 'readonly', host: 'localhost' }, }, }; const createDbSql = createDatabase(dbConfig.database, { ifNotExists: true }); console.log(createDbSql); // 'CREATE DATABASE IF NOT EXISTS `example`;' const createUserSql = createUser(dbConfig.users.readonly, { ifNotExists: true }); console.log(createUserSql); // "CREATE USER IF NOT EXISTS 'readonly'@'localhost'" const grantSql = grant({ privileges: ['EXECUTE', 'SELECT'], on: { level: { database: dbConfig.database } }, to: dbConfig.users.readonly, }); console.log(grantSql); // "GRANT EXECUTE, SELECT ON `example`.* TO 'readonly'@'localhost'"
Debug
Known issues
gotchaThis library does NOT connect to MySQL or execute SQL; it only generates SQL strings. You must use a separate driver (e.g., mysql, mysql2) to run them.
fix
Pair with mysql or mysql2 to execute the generated SQL.
affects: *
gotchaVersion 0.1.1 is the only release and is quite old (2017-2018). There are no recent updates or security patches. Consider using Squel or knex for more maintained alternatives.
fix
Evaluate if Squel or knex meets your needs; they are actively maintained.
affects: *
gotchaThe library uses ES modules (import/export) but the package.json does not have 'type': 'module'. If using Node <12, you may need to use the .mjs extension or a transpiler.
fix
Rename files to .mjs or use Babel/TypeScript to transpile.
affects: *
gotchaNo TypeScript type definitions are provided by the package. You may need to declare types manually or use @types if available (none found).
fix
Create a .d.ts file for your project or extend with custom typings.
affects: *
Errors
Common errors & fixes
Cannot find module 'mysql-admin-sql-gen'
The package is not installed or is not in node_modules.
fix
Run 'npm install mysql-admin-sql-gen' to install the package.
SyntaxError: Unexpected token 'export'
The package uses ES module syntax but your environment (Node or bundler) expects CommonJS.
fix
If using Node, rename your file to .mjs or set 'type': 'module' in package.json. If using a bundler, ensure it handles ES modules.
TypeError: createDatabase is not a function
The import statement is incorrect; likely importing default instead of named export.
fix
Use 'import { createDatabase } from 'mysql-admin-sql-gen'.'
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
mysql-admin-sql-gen — npm install mysql-admin-sql-gen · libregistry