# parsesql

- マニュアル
- 標準ライブラリ
- 索引

検索
分類:

The `parsesql` module implements a high performance SQL file parser. It parses PostgreSQL syntax and the SQL ANSI standard.

この API は不安定です。

# インポート

strutils, lexbase, streams

# 型

    SqlLexer = object of BaseLexer
      filename: string

  the parser object. ソース 編集

    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, nkGroup, nkLimit, nkHaving, nkOrder,
      nkJoin, nkDesc, nkUnion, nkIntersect, nkExcept, nkColumnList, nkValueList, nkWhere,
      nkCreateTable, nkCreateTableIfNotExists, nkCreateType, nkCreateTypeIfNotExists,
      nkCreateIndex, nkCreateIndexIfNotExists, nkEnumDef

  kind of SQL abstract syntax tree Source Edit

    SqlParseError = object of ValueError

  Invalid SQL encountered Source Edit

    SqlNode = ref SqlNodeObj

  an SQL abstract syntax tree node 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

    SqlParser = object of SqlLexer
      tok: Token

  SQL parser object Source Edit

# プロシージャ

    proc newNode(k: SqlNodeKind): SqlNode {...}{.raises: [], tags: [].}

  ソース 編集

    proc newNode(k: SqlNodeKind; s: string): SqlNode {...}{.raises: [], tags: [].}

  ソース 編集

    proc newNode(k: SqlNodeKind; sons: seq[SqlNode]): SqlNode {...}{.raises: [], tags: [].}

  ソース 編集

    proc len(n: SqlNode): int {...}{.raises: [], tags: [].}

  ソース 編集

    proc `[]`(n: SqlNode; i: int): SqlNode {...}{.raises: [], tags: [].}

  ソース 編集

    proc `[]`(n: SqlNode; i: BackwardsIndex): SqlNode {...}{.raises: [], tags: [].}

  ソース 編集

    proc add(father, n: SqlNode) {...}{.raises: [], tags: [].}

  ソース 編集

    proc renderSQL(n: SqlNode; upperCase = false): string {...}{.raises: [Exception],
        tags: [RootEffect].}

  Converts an SQL abstract syntax tree to its string representation. ソース 編集

    proc `$`(n: SqlNode): string {...}{.raises: [Exception], tags: [RootEffect].}

  an alias for `renderSQL`. ソース 編集

    proc treeRepr(s: SqlNode): string {...}{.raises: [], tags: [].}

  ソース 編集

    proc parseSQL(input: Stream; filename: string): SqlNode {...}{.raises: [Defect, IOError,
        OSError, Defect, IOError, OSError, ValueError, SqlParseError, Exception],
        tags: [ReadIOEffect, RootEffect, WriteIOEffect].}

  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. ソース 編集

    proc parseSQL(input: string; filename = ""): SqlNode {...}{.
        raises: [Defect, IOError, OSError, ValueError, SqlParseError, Exception],
        tags: [ReadIOEffect, RootEffect, WriteIOEffect].}

  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. ソース 編集