Registry / database / sync-mysql-database

sync-mysql-database

JSON →
library2.3.4jsnpmunverified

Synchronous MySQL database manager built on top of sync-mysql. Current stable version is 2.3.4. Provides a class hierarchy for synchronous database operations including table creation from JSON schema, query building with insert/select/get methods, and is designed for Node.js. Differentiates from async drivers by offering blocking calls, suitable for scripts and CLIs. Requires auth.json with database field and structure.json for table definitions. Release cadence is sporadic.

npm install sync-mysql-database
INSTALL
IMPORT
SIG · SYNC-MYSQL-DATABAS
S
sync-mysql-database
databasejavascriptv2.3.4
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.

Database
const { Database } = require('sync-mysql-database');
const Database = require('sync-mysql-database');
Named export via destructuring. CommonJS only; no ESM support.
Database
const Database = require('sync-mysql-database').Database;
const Database = require('sync-mysql-database');
Alternative correct import without destructuring.
Query
const { Query } = require('sync-mysql-database');
const Query = require('sync-mysql-database').Query;
Query class also exported; incorrect if directly assigned.

Shows synchronous MySQL operations: create database from auth and structure JSON, insert a row, and retrieve all rows.

const { Database } = require('sync-mysql-database'); const auth = { user: 'root', host: 'localhost', password: 'password', database: 'testdb' }; const struct = { version: '1', tables: [ { name: 'users', columns: [ { name: 'id', type: 'INTEGER', constraints: 'auto_increment' }, { name: 'username', type: 'varchar(20)' }, { name: 'password', type: 'char(20)' } ], primary_key: 'id' } ] }; const db = new Database(auth, struct); db.getTable('users').query().select('username', 'password').insert('user1', 'secret'); console.log(db.getTable('users').query().get());
Debug
Known issues
gotchaauth.json must include 'database' field; sync-mysql package itself does not require it.
fix
Always provide the 'database' property in the auth object.
affects: >=0.0.0
gotchaQuery methods like insert() modify internal state and do not execute until get() is called for select, or similar finalizer. Chaining order matters.
fix
Ensure you call a terminal method (e.g., get(), execute()) after building the query.
affects: >=0.0.0
deprecatedThis package may not be actively maintained; last update unknown.
fix
Consider migrating to async MySQL drivers like mysql2 with synchronous wrapper via deasync or use better-sqlite3 for SQLite.
affects: >=0.0.0
Errors
Common errors & fixes
Error: sync-mysql is not installed
Missing peer dependency sync-mysql.
fix
Run: npm install sync-mysql
TypeError: Database is not a constructor
Incorrect import: using default import instead of named destructuring.
fix
Use const { Database } = require('sync-mysql-database');
Error: 'auth' object must have a 'database' property
Missing database field in auth object.
fix
Add 'database' to the auth object, e.g., { user, host, password, database: 'mydb' }.
Upgrade
Version history
2.3.4latest on npm
Audit
Dependencies
sync-mysqlrequiredCore synchronous MySQL driver that this package wraps.
Agent activity
16 hits · last 30 days
node
12
Meta
1
Amazon
1
OpenAI (training)
1
Resources
sync-mysql-database — npm install sync-mysql-database · libregistry