taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
750 stars 172 forks source link

Expose more types outside. #1949

Open create-new-entity opened 4 weeks ago

create-new-entity commented 4 weeks ago

Issue Once we parse the query and get the JSON object, we further manipulate the JSON object to get it into a certain shape. To do that we use smaller helper functions in between. It would be nice if we could define types for this smaller functions.

Since these functions take different parts of the JSON and those parts already have types defined within the library ( for example, CreateConstraintForeign, CreateConstraintCheck and so on ), would it be possible to expose those types so that we can utilize them?

Database Engine Snowflake

To Reproduce -the node-sql-parser version: 5.2.0 -the node version: 20.11.1

Expected behavior Allow import statements for types. For example:

import {  CreateColumnDefinition, CreateConstraintForeign, CreateConstraintDefinition } from 'node-sql-parser'

const extractIsFK = ( alterASTs: Alter[], fkConstraintASTs: CreateConstraintForeign[] ): boolean => {
     // Doing some stuffs here
     return some_boolean_value
}

Example in a forked repo Please also take a look at this PR in this forked repo.

and thanks a lot for this nice library.