Registry / database / cyber-mysql-openai

cyber-mysql-openai

JSON →
library0.3.3jsnpmunverified

Cyber-MySQL-OpenAI is a Node.js library that translates natural language questions into SQL, executes them against MySQL databases, and returns results with human-readable explanations. Version 0.3.3 provides features such as self-correcting error handling (up to 3 reflection attempts), structured output via OpenAI function calling, business context awareness, foreign key relationship detection, confidence scoring, multi-language support (English and Spanish), in-memory caching, token optimization, and query validation. It is actively maintained with frequent updates and full TypeScript support.

npm install cyber-mysql-openai
INSTALL
IMPORT
SIG · CYBER-MYSQL-OPENAI
C
cyber-mysql-openai
databasejavascriptv0.3.3
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.

Translator
import { Translator } from 'cyber-mysql-openai'
import CyberMySQLOpenAI from 'cyber-mysql-openai'
The main class is exported as a named export. Default import is not available.
TranslatorConfig
import type { TranslatorConfig } from 'cyber-mysql-openai'
import { TranslatorConfig } from 'cyber-mysql-openai'
TranslatorConfig is a TypeScript type. Use `import type` when only needing the type.
QueryResult
import type { QueryResult } from 'cyber-mysql-openai'
QueryResult is a TypeScript type representing the result of a query execution.

Demonstrates initializing a Translator with MySQL and OpenAI configs, then querying for user registrations.

import { Translator } from 'cyber-mysql-openai'; const translator = new Translator({ mysql: { host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }, openai: { apiKey: process.env.OPENAI_API_KEY ?? '' } }); async function main() { const result = await translator.query('How many users registered last month?'); console.log(result); } main().catch(console.error);
Debug
Known issues
breakingVersion 0.3.0 changed the constructor signature requiring nested 'mysql' and 'openai' objects. Older config flattened is not supported.
fix
Wrap your config as { mysql: {...}, openai: {...} }
affects: <0.3.0
gotchaThe library uses OpenAI function calling and expects a model that supports it (e.g., gpt-3.5-turbo or gpt-4). Using incompatible models will cause errors.
fix
Specify a compatible model in translator config: { openai: { model: 'gpt-4' } }
affects: >=0.1.0
gotchaThe cache is in-memory and not persisted. Restarting the application clears all cached data.
fix
Implement external caching (e.g., Redis) if persistence is needed.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'cyber-mysql-openai'
Package not installed or not imported correctly.
fix
Run: npm install cyber-mysql-openai
TypeError: translator.query is not a function
Using default import instead of named import.
fix
Use: import { Translator } from 'cyber-mysql-openai'
OpenAI API error: 401 - Incorrect API key provided
Missing or invalid OPENAI_API_KEY.
fix
Set process.env.OPENAI_API_KEY to a valid key.
Error: ER_ACCESS_DENIED: Access denied for user
Invalid MySQL credentials or insufficient privileges.
fix
Check MYSQL_USER and MYSQL_PASSWORD, and ensure the user has access to the database.
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
mysql2requiredRequired for connecting to and querying MySQL databases.
openairequiredRequired for interacting with OpenAI's API for natural language processing.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
2
Resources
cyber-mysql-openai — npm install cyber-mysql-openai · libregistry