WOrmPostgresql

WOrmPostgresql

new WOrmPostgresql(optopt) → {Object}

Description:
  • 操作資料庫(PostgreSQL)

Source:
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'postgresql://127.0.0.1:5432'

輸入連接資料庫字串,預設'postgresql://127.0.0.1:5432'

db String <optional>
'worm'

輸入使用資料庫名稱字串,預設'worm'

cl String <optional>
'test'

輸入使用資料表名稱字串,預設'test'

useCache Boolean <optional>
false

輸入是否使用select快取,適用於單程序操作,預設false

Returns:

回傳操作資料庫物件,各事件功能詳見說明

Type
Object

Methods

(async, static) createTable(cl, pk, arr) → {Promise}

Description:
  • 創建資料表

Source:
Parameters:
Name Type Description
cl String

輸入資料表名字串

pk String

輸入主鍵字串

arr Array | Object

輸入數據物件陣列或數據物件

Returns:

回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息

Type
Promise

(async, static) del(data) → {Promise}

Description:
  • 刪除數據

Source:
Parameters:
Name Type Description
data Object | Array

輸入數據物件或陣列

Returns:

回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息

Type
Promise

(async, static) delAll(findopt) → {Promise}

Description:
  • 刪除全部數據,需與del分開,避免未傳數據導致直接刪除全表

Source:
Parameters:
Name Type Attributes Default Description
find Object <optional>
{}

輸入刪除條件物件

Returns:

回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息

Type
Promise

(async, static) insert(data) → {Promise}

Description:
  • 插入數據

Source:
Parameters:
Name Type Description
data Object | Array

輸入數據物件或陣列

Returns:

回傳Promise,resolve回傳插入結果,reject回傳錯誤訊息

Type
Promise

(async, static) save(data, optionopt) → {Promise}

Description:
  • 儲存數據

Source:
Parameters:
Name Type Attributes Default Description
data Object | Array

輸入數據物件或陣列

option Object <optional>
{}

輸入設定物件,預設為{}

Properties
Name Type Attributes Default Description
autoInsert boolean <optional>
true

輸入是否於儲存時發現原本無數據,則自動改以插入處理,預設為true

Returns:

回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息

Type
Promise

(async, static) select(findopt, orderopt) → {Promise}

Description:
  • 查詢數據

Source:
Parameters:
Name Type Attributes Default Description
find Object <optional>
{}

輸入查詢條件物件

order Object <optional>
{}

輸入排序條件物件

Returns:

回傳Promise,resolve回傳數據,reject回傳錯誤訊息

Type
Promise