本文整理匯總了TypeScript中prisma-cli-engine.Client.download方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client.download方法的具體用法?TypeScript Client.download怎麽用?TypeScript Client.download使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prisma-cli-engine.Client
的用法示例。
在下文中一共展示了Client.download方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: downloadFiles
async downloadFiles(
fileType: FileType,
serviceName: string,
stage: string,
token?: string,
workspaceSlug?: string,
) {
const before = Date.now()
this.out.action.start(`Downloading ${fileType}`)
let cursor: ExportCursor = {
table: 0,
row: 0,
field: 0,
array: 0,
}
const cursorSum = c =>
Object.keys(c).reduce((acc, curr) => acc + c[curr], 0)
const leadingZero = (n: number, zeroes: number = 6) =>
repeat('0', Math.max(zeroes - String(n).length, 0)) + n
let count = 1
const filesDir = path.join(this.exportDir, `${fileType}/`)
while (cursorSum(cursor) >= 0) {
const data = await this.client.download(
serviceName,
stage,
JSON.stringify({
fileType,
cursor,
}),
token,
workspaceSlug,
)
debug(data)
if (data.errors) {
throw new Error(data.errors)
}
const jsonString = JSON.stringify({
valueType: fileType,
values: data.out.jsonElements,
})
fs.writeFileSync(
path.join(filesDir, `${leadingZero(count)}.json`),
jsonString,
)
cursor = data.cursor
count++
}
this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
}