The parsesql module implements a high performance SQL file parser. It parses PostgreSQL syntax and the SQL ANSI standard.
Unstable API.
Types
SqlNode = ref SqlNodeObj
- an SQL abstract syntax tree node Source Edit
SqlNodeKind = enum nkNone, nkIdent, nkQuotedIdent, nkStringLit, nkBitStringLit, nkHexStringLit, nkIntegerLit, nkNumericLit, nkPrimaryKey, nkForeignKey, nkNotNull, nkNull, nkStmtList, nkDot, nkDotDot, nkPrefix, nkInfix, nkCall, nkPrGroup, nkColumnReference, nkReferences, nkDefault, nkCheck, nkConstraint, nkUnique, nkIdentity, nkColumnDef, ## name, datatype, constraints nkInsert, nkUpdate, nkDelete, nkSelect, nkSelectDistinct, nkSelectColumns, nkSelectPair, nkAsgn, nkFrom, nkFromItemPair, nkJoin, nkNaturalJoin, nkUsing, nkGroup, nkLimit, nkOffset, nkHaving, nkOrder, nkDesc, nkUnion, nkIntersect, nkExcept, nkColumnList, nkValueList, nkWhere, nkCreateTable, nkCreateTableIfNotExists, nkCreateType, nkCreateTypeIfNotExists, nkCreateIndex, nkCreateIndexIfNotExists, nkEnumDef
- kind of SQL abstract syntax tree Source Edit
SqlNodeObj = object case kind*: SqlNodeKind ## kind of syntax tree of LiteralNodes: strVal*: string ## AST leaf: the identifier, numeric literal ## string literal, etc. else: sons*: seq[SqlNode] ## the node's children
- an SQL abstract syntax tree node Source Edit
SqlParseError = object of ValueError
- Invalid SQL encountered Source Edit
Procs
proc newNode(k: SqlNodeKind): SqlNode {....raises: [], tags: [], forbids: [].}
- Source Edit
proc parseSql(input: Stream; filename: string; considerTypeParams = false): SqlNode {....raises: [ IOError, OSError, IOError, OSError, ValueError, SqlParseError, Exception], tags: [ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].}
- parses the SQL from input into an AST and returns the AST. filename is only used for error messages. Syntax errors raise an SqlParseError exception. Source Edit
proc parseSql(input: string; filename = ""; considerTypeParams = false): SqlNode {. ...raises: [IOError, OSError, ValueError, SqlParseError, Exception], tags: [ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].}
- parses the SQL from input into an AST and returns the AST. filename is only used for error messages. Syntax errors raise an SqlParseError exception. Source Edit