new WOrmReladb(optopt) → {Object}
- Description:
操作關聯式資料庫
注意: 各model內id欄位不是主鍵(primary key)時需要強制更改成為主鍵,否則sequelize無法匯入
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳操作資料庫物件,各事件功能詳見說明
- Type
- Object
Methods
(async, static) closeSequelize() → {Promise}
- Description:
關閉sequelize
- Source:
Returns:
回傳Promise,resolve代表關閉成功,reject回傳錯誤訊息
- Type
- Promise
(async, static) createStorage() → {Promise}
- Description:
創建sqlite資料庫檔案
- Source:
Returns:
回傳Promise,resolve回傳創建結果,reject回傳錯誤訊息
- Type
- Promise
(async, static) del(data, optionopt) → {Promise}
- Description:
刪除數據
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | Array | 輸入數據物件或陣列,會查找各數據的opt.pk值,有存在者就刪除 |
|||||||||||||||||
option |
Object |
<optional> |
{}
|
輸入設定物件,預設為{} Properties
|
Returns:
回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息
- Type
- Promise
(async, static) delAll(findopt, optionopt) → {Promise}
- Description:
刪除數據,需與del分開,避免未傳數據導致直接刪除全表
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find |
Object |
<optional> |
{}
|
輸入刪除條件物件,不給予find則代表刪除全部數據 |
|||||||||||||||
option |
Object |
<optional> |
{}
|
輸入設定物件,預設為{} Properties
|
Returns:
回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息
- Type
- Promise
(static) genModelsByDB(optionopt) → {Promise}
- Description:
由指定資料庫生成各資料表的models資料
目前僅能產生js檔格式,且mssql欄位為nvarchar(MAX)無法自動轉成TEXT格式
include from: w-auto-sequelize
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
option |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise,resolve回傳產生的models資料,reject回傳錯誤訊息
- Type
- Promise
(static) genModelsByTabs(fdopt, tabsopt, optopt)
- Description:
由資料表物件生成各資料表的models資料
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fd |
String |
<optional> |
'./models'
|
輸入models儲存的資料夾名稱字串,預設'./models' |
||||||||||
tabs |
Object |
<optional> |
{}
|
輸入各資料表物件,預設{} |
||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
(async, static) genTransaction() → {Promise}
- Description:
產生交易transaction狀態物件,當使用transaction時資料庫會上鎖,只能供調用的連線操作處理
- Source:
Returns:
回傳Promise,resolve回傳交易transaction物件,reject回傳錯誤訊息
- Type
- Promise
(async, static) initSequelize(syncopt) → {Promise}
- Description:
初始化sequelize
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sync |
Boolean |
<optional> |
false
|
輸入當importModels匯入models時是否使用同步方式,將models資料變更至資料庫當中,此功能提供給createStorage之用 |
Returns:
回傳Promise,resolve代表關閉成功,reject回傳錯誤訊息
- Type
- Promise
(async, static) insert(data, optionopt) → {Promise}
- Description:
插入數據,插入同樣數據會自動產生不同_id,故insert前需自行判斷有無重複
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | Array | 輸入數據物件或陣列 |
|||||||||||||||||
option |
Object |
<optional> |
{}
|
輸入設定物件,預設為{} Properties
|
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
|
Returns:
回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息
- Type
- Promise
(async, static) select(findopt, optionopt) → {Promise}
- Description:
查詢數據
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find |
Object |
<optional> |
{}
|
輸入查詢條件物件 |
|||||||||||||||
option |
Object |
<optional> |
{}
|
輸入設定物件,預設為{} Properties
|
Returns:
回傳Promise,resolve回傳數據,reject回傳錯誤訊息
- Type
- Promise