ts-mysql-analyzer
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

ts-mysql-analyzer

Alt Text

A MySQL query analyzer.

Alt Text

Features

  • Detects MySQL syntax errors
  • Detects invalid table names/column names (powered by your schema)
  • Type checking (powered by your schema)
  • Optimization suggestions (e.g. query for column with missing index)
  • Supports custom parser options (e.g. MySQL version, character sets, etc.)
  • Supports multiple statements

Installation

yarn add ts-mysql-analyzer
# or 
npm install ts-mysql-analyzer

Usage

import { MySQLAnalyzer } from 'ts-mysql-analyzer'
import { MySQLSchema } from 'ts-mysql-schema'
 
const mySQLSchema = new MySQLSchema({
  uri: 'mysql://root@127.0.0.1:3310/test'
})
 
const analyzer = new MySQLAnalyzer({
  schema: await mySQLSchema.getSchema()
})
 
// "'SELT' is not valid at this position."
console.log(analyzer.analyze('SELT * FROM user'))
 
// "Table 'invalid_table' does not exist in database 'test'. Did you mean 'posts'?"
console.log(analyzer.analyze('SELECT * FROM invalid_table'))
 
// "Column 'invalid_column' does not exist in table 'users'. Did you mean 'name'?"
console.log(analyzer.analyze('SELECT invalid_column FROM users'))
 
// "Type boolean is not assignable to type string."
console.log(analyzer.analyze('SELECT * FROM users WHERE id = true'))
 
// "You can optimize this query by adding a MySQL index for column 'name'."
console.log(analyzer.analyze('SELECT * FROM users WHERE name = "some-name"'))

Related

License

MIT


stevenmiller888.github.io  ·  GitHub @stevenmiller888  ·  Twitter @stevenmiller888

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    1,521
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    1,521
  • 0.2.0
    3
  • 0.1.0
    3
  • 0.0.2
    2
  • 0.0.1
    2

Package Sidebar

Install

npm i ts-mysql-analyzer

Weekly Downloads

594

Version

0.3.0

License

MIT

Unpacked Size

346 kB

Total Files

31

Last publish

Collaborators

  • npm-support