Global

Methods

genIndex(fdSrc, fdIndex, optopt)

Description:
  • 由各資料表定義*.mjs檔產生資料表收集物件ds

Source:
Example
import genIndex from 'w-data-collector/src/genIndex.mjs'

genIndex('./src/schema/tables', './src/schema', {})
// => genIndex done
Parameters:
Name Type Attributes Default Description
fdSrc String

輸入各資料表定義*.mjs檔案所在資料夾

fdIndex String

輸入產生index.mjs檔案需儲存至的資料夾,主要是跟各資料表定義*.mjs檔計算相對路徑供程式碼import用

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
fpBuild String <optional>
'w-data-collector/src/build.mjs'

輸入程式碼所需import之再處理資料表定義*.mjs檔的build函數,預設為'w-data-collector/src/build.mjs'

fnIndex String <optional>
'index.mjs'

輸入產生ds所需程式碼index.mjs檔案的名稱,預設為'index.mjs',實際檔案儲存位置為fdIndex下fnIndex

(async) genTestdata(ds, wo, optopt) → {Promise}

Description:
  • 由資料表收集物件ds與資料表控制物件wo產生測試資料,並儲存至資料庫

Source:
Example
import genTestdata from 'w-data-collector/src/genTestdata.mjs'
import ds from './index.mjs'
import { woItems } from '../../server/mOrm.mjs'

genTestdata(ds, woItems, {})
// => genTestdata done
Parameters:
Name Type Attributes Default Description
ds Object

輸入資料表收集物件,ds也就是import由genIndex產生的index.mjs,其內各key代表各資料表,值代表各資料表設定與操作函數例如settings、funNew或funTestAndSave等

wo Object

輸入資料表控制物件,各key代表各資料表,值代表各資料表操作函數例如insert、save、del等

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
useGenModels Boolean <optional>
false

輸入是否呼叫genModels,若資料庫與ORM為關聯資料庫時需設定為true,同時還需給予opt.genModelsByTabs。預設為false

genModelsByTabs function <optional>
null

輸入可由ds與wo產生models的函數,若資料庫與ORM為關聯資料庫時則需給予,可由程式碼import genModelsByTabs from 'w-orm-reladb/src/genModelsByTabs.mjs'取得genModelsByTabs,並再設定給opt.genModelsByTabs

fdModels String <optional>
'./models'

輸入產生models放置的資料夾位置,預設為工作路徑下的models

Returns:

回傳Promise,resolve代表產生成功,reject代表產生失敗

Type
Promise

getItemsFail(rs, data) → {Array}

Description:
  • 由ORM逐筆函數(save、del)之回傳結果取出失敗者

    依w-orm系列規格,逐筆函數回傳與輸入等長保序之陣列,單筆失敗時整批仍resolve,該筆以ok為0並附err回報,須由呼叫端逐筆檢查。 主鍵未命中(save於autoInsert為false時查無主鍵、del查無主鍵)屬正常結果,其ok為1而以n為0表示,不視為失敗。 逐筆結果不含主鍵,故主鍵取自輸入同位置數據之id。

Source:
Example
import getItemsFail from 'w-data-collector/src/getItemsFail.mjs'

let data = [{ id: 'id-a' }, { id: 'id-b' }, { id: 'id-c' }]
let rs = [
    { n: 1, nInserted: 1, nModified: 0, ok: 1 }, //插入
    { n: 0, nInserted: 0, nModified: 0, ok: 1 }, //主鍵未命中, 屬正常結果
    { n: 1, nInserted: 0, nModified: 0, ok: 0, err: 'E' }, //該筆失敗
]
console.log(getItemsFail(rs, data))
// => [ { k: 2, id: 'id-c', err: 'E' } ]
Parameters:
Name Type Description
rs Array

輸入ORM逐筆函數(save、del)之回傳結果陣列,非陣列時(未依規格之ORM)無從逐筆檢查而回傳空陣列

data Object | Array

輸入呼叫ORM逐筆函數時之數據物件或陣列,為單一物件時視為長度為1之陣列

Returns:

回傳失敗者陣列,各筆為{k,id,err},k為該筆於輸入內之位置,id為輸入同位置數據之id,err為ORM回報之錯誤訊息(未附時為空字串),無失敗者回傳空陣列

Type
Array