本文整理汇总了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`))
}