WOrmMssql

WOrmMssql

new WOrmMssql(optopt) → {Object}

Source:

操作資料庫(Microsoft SQL)

注意: 各model內id欄位不是主鍵(primary key)時需要強制更改成為主鍵,否則sequelize無法匯入

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

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'mssql://username:password@localhost:1433'

輸入連接資料庫字串,預設'mssql://username:password@localhost:1433'

db String <optional>
'worm'

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

cl String <optional>
'test'

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

fdModels String <optional>
'models'

輸入資料表models(各檔為*.js)所在資料夾字串,預設'models'

logging Boolean <optional>
false

輸入是否輸出實際執行的sql指令,預設false

pk String <optional>
'id'

輸入數據主鍵字串,預設'id'

autoGenPK Boolean <optional>
true

輸入若數據pk(id)欄位沒給時則自動給予隨機uuid,預設true

Returns:

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

Type
Object

Methods

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

Source:

刪除數據

Parameters:
Name Type Description
data Object | Array

輸入數據物件或陣列

Returns:

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

Type
Promise

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

Source:

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

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

輸入刪除條件物件

Returns:

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

Type
Promise

(static) genModels(optionopt) → {Promise}

Source:

由指定資料庫生成各表的models資料

include from: w-auto-sequelize

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

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
database String <optional>
null

輸入資料庫名稱字串,預設null

username String <optional>
null

輸入使用者名稱字串,預設null

password String <optional>
null

輸入密碼字串,預設null

dialect String <optional>
null

輸入資料庫種類字串,預設null,可選'mysql', 'mariadb', 'sqlite', 'postgres', 'mssql'

directory String <optional>
'./models'

輸入models儲存的資料夾名稱字串,預設'./models'

host String <optional>
'localhost'

輸入連線主機host位址字串,預設'localhost'

port Integer <optional>
null

輸入連線主機port整數,預設null

Returns:

回傳Promise,resolve回傳產生的models資料,reject回傳錯誤訊息

Type
Promise

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

Source:

插入數據,插入同樣數據會自動產生不同_id,故insert前需自行判斷有無重複

Parameters:
Name Type Description
data Object | Array

輸入數據物件或陣列

Returns:

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

Type
Promise

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

Source:

儲存數據

Parameters:
Name Type Attributes Default Description
data Object | Array

輸入數據物件或陣列

option Object <optional>
{}

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

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

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

atomic boolean <optional>
false

輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false

Returns:

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

Type
Promise

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

Source:

查詢數據

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

輸入查詢條件物件

Returns:

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

Type
Promise