nene / sql-parser-cst

Parses SQL into Concrete Syntax Tree (CST)
GNU General Public License v2.0
115 stars 7 forks source link

Postgres support (user defined types) #78

Open nene opened 4 weeks ago

nene commented 4 weeks ago
maheshsundaram commented 3 weeks ago

Thanks for documenting this! I would be glad to help out if I can figure out how. If you have any time and is convenient for you, can you point me to where I can begin?

nene commented 3 weeks ago

I guess you can look at existing commits to see how. This one might be a good start: https://github.com/nene/sql-parser-cst/commit/00adcae78bc799bb6aaa0b146b0d7aba9ff89590

The trickiest bit is figuring out the structure of the resulting syntax tree. For CREATE TYPE I guess it should be something like:

export interface CreateTypeStmt extends BaseNode {
  type: "create_type_stmt";
  createKw: Keyword<"CREATE">;
  typeKw: Keyword<"TYPE">;
  name: EntityName;
  // ENUM definition is probably the simplest, though others should fit here as well
  definition?: AsClause<EnumTypeDefinition>;
}

export interface EnumTypeDefinition extends BaseNode {
  type: "enum_type_definition";
  enumKw: Keyword<"ENUM">;
  values: ParenExpr<ListExpr<StringLiteral>>;
}