11.5 表格 CRUD 函數

TableSelectFunction

Table.select()collection.find() 使用不同的方法來排序結果。Table.select() 遵循 SQL 語言命名並將排序方法稱為 orderBy()Collection.find() 則不遵循。使用 sort() 方法來排序 Collection.find() 傳回的結果。在此,與 SQL 標準的相近性比 API 的一致性更重要。

以 EBNF 顯示的此函數語法為

TableSelectFunction
  ::= '.select(' ProjectedSearchExprStrList? ')' ( '.where(' SearchConditionStr ')' )?
      ( '.groupBy(' SearchExprStrList ')' )? ( '.having(' SearchConditionStr ')' )?
      ( '.orderBy(' SortExprStrList ')' )? ( '.limit(' NumberOfRows ')' ( '.offset(' NumberOfRows ')' )? )?
      ( '.lockExclusive(' LockContention ')' | '.lockShared(' LockContention ')' )? 
      ( '.bind(' ( PlaceholderValues ) ')' )*
      ( '.execute()' )?

圖 11.15 TableSelectFunction

Image shows the syntax in EBNF form as described in the preceding text.

TableInsertFunction

以 EBNF 顯示的此函數語法為

TableInsertFunction
  ::= '.insert(' ( TableFields )? ')'
        ( '.values(' ExprOrLiteral (',' ExprOrLiteral)* ')' )+
        ( '.execute()' )?

圖 11.16 TableInsertFunction

Image shows the syntax in EBNF form as described in the preceding text.

TableUpdateFunction

以 EBNF 顯示的此函數語法為

TableUpdateFunction
  ::= '.update()'
      ( '.set(' TableField ',' ExprOrLiteral ')' )+ '.where(' SearchConditionStr ')'
      ( '.orderBy(' SortExprStrList ')' )? ( '.limit(' NumberOfRows ')' )?
      ( '.bind(' ( PlaceholderValues ) ')' )*
      ( '.execute()' )?

圖 11.17 TableUpdateFunction

Image shows the syntax in EBNF form as described in the preceding text.

TableDeleteFunction

以 EBNF 顯示的此函數語法為

TableDeleteFunction
  ::= '.delete()' '.where(' SearchConditionStr ')'
      ( '.orderBy(' SortExprStrList ')' )? ( '.limit(' NumberOfRows ')' )?
      ( '.bind(' ( PlaceholderValues ) ')' )*
      ( '.execute()' )?

圖 11.18 TableDeleteFunction

Image shows the syntax in EBNF form as described in the preceding text.