{"id":43870,"library":"sql-ast","title":"sql-ast","description":"A MySQL parser that converts mysqldump output into an AST. Version 0.3.0 is the latest stable release, but the library is early-stage with limited feature coverage. It tokenizes SQL input into word, ident, punct, number, string, variable, and version tokens, and builds AST nodes for statements, actions, columns, indexes, rows, and more. Differentiated by its focus on mysqldump output and minimal dependencies. Development is infrequent; community contributions are welcome but not actively maintained.","status":"maintenance","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/aleclarson/sql-ast","tags":["javascript"],"install":[{"cmd":"npm install sql-ast","lang":"bash","label":"npm"},{"cmd":"yarn add sql-ast","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-ast","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package does not provide ESM exports; CommonJS only.","wrong":"import { parse } from 'sql-ast';","symbol":"parse","correct":"const { parse } = require('sql-ast');"},{"note":"All exported classes are available as named exports from the CommonJS module.","wrong":"const Node = require('sql-ast').NodeClass;","symbol":"Node","correct":"const { Node } = require('sql-ast');"},{"note":"CommonJS only; ESM imports will fail.","wrong":"import { Statement } from 'sql-ast';","symbol":"Statement","correct":"const { Statement } = require('sql-ast');"}],"quickstart":{"code":"const { parse } = require('sql-ast');\n\nconst input = `CREATE TABLE users (\n  id INT PRIMARY KEY AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL\n) ENGINE=InnoDB;`;\n\nconst ast = parse(input);\nconsole.log(JSON.stringify(ast, null, 2));","lang":"javascript","description":"Parses a CREATE TABLE statement from a SQL string and logs the resulting AST array as JSON."},"warnings":[{"fix":"Iterate over the array returned by parse() to access individual Statement nodes.","message":"The parse function returns an array of nodes, not a single root node.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Do not rely on token positions for whitespace; use AST node positions for accurate source mapping.","message":"Whitespace and comments (except /*! */) are not tokenized; they are stripped during parsing.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider using more mature SQL parsers like node-sql-parser or sql.js for broader SQL support.","message":"Feature set is very limited; does not support many SQL dialects or complex statements.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.3.0':15 'action':52 'activ':77 'ast':3,13,48 'build':47 'column':53 'communiti':71 'contribut':72 'convert':8 'coverag':31 'depend':67 'develop':68 'differenti':58 'earli':26 'early-stag':25 'featur':30 'focus':61 'ident':38 'index':54 'infrequ':70 'input':35 'javascript':79 'latest':18 'librari':23 'limit':29 'maintain':78 'minim':66 'mysql':5 'mysqldump':9,63 'node':49 'number':40 'output':10,64 'parser':6 'punct':39 'releas':20 'row':55 'sql':2,34 'sql-ast':1 'stabl':19 'stage':27 'statement':51 'string':41 'token':33,45 'variabl':42 'version':14,44 'welcom':74 'word':37","created_at":"2026-06-05T17:01:52.303454+00:00","updated_at":"2026-06-05T17:01:52.303454+00:00","problems":[{"fix":"Install using `npm install sql-ast` and ensure CommonJS usage (require, not import).","cause":"Package not installed or used in an ESM context without proper require.","error":"Cannot find module 'sql-ast'"},{"fix":"Use `const { parse } = require('sql-ast');`","cause":"Importing the default export instead of named export.","error":"TypeError: parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/aleclarson/sql-ast#readme","github":"https://github.com/aleclarson/sql-ast","docs":null,"changelog":null,"pypi":null,"npm":"sql-ast","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}