本文整理匯總了TypeScript中prisma-cli-engine.Client類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client類的具體用法?TypeScript Client怎麽用?TypeScript Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: fetchAndPrintSchema
export async function fetchAndPrintSchema(
client: Client,
serviceName: string,
stageName: string,
token?: string,
): Promise<string> {
const introspection = await client.introspect(serviceName, stageName, token)
const schema = buildClientSchema(introspection)
const sdl = printSchema(schema)
const document = parse(sdl)
const groupedDefinitions = groupBy(document.definitions, classifyDefinition)
let sortedDefinitions: DefinitionNode[] = []
typesOrder.map(type => {
const definitions = groupedDefinitions[type]
sortedDefinitions = sortedDefinitions.concat(definitions)
})
let newSdl = print({
kind: Kind.DOCUMENT,
definitions: sortedDefinitions,
})
const newDocument = parse(newSdl)
// add comments to document
let countOffset = 0
let charOffset = 0
typesOrder.forEach((type, index) => {
if (!groupedDefinitions[type]) {
return
}
const definitionCount = groupedDefinitions[type].length
const definitions = newDocument.definitions.slice(
countOffset,
definitionCount,
)
const start = definitions[0].loc!.start
const comment = `\
${index > 0 ? '\n' : ''}#
# ${descriptions[type]}
#\n\n`
newSdl =
newSdl.slice(0, start + charOffset) +
comment +
newSdl.slice(start + charOffset)
charOffset += comment.length
countOffset += definitionCount
})
const header = `# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
# DO NOT EDIT THIS FILE DIRECTLY\n\n`
return header + newSdl
}
示例2: 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`))
}
示例3: reset
async reset(serviceName, stageName) {
const before = Date.now()
this.out.action.start(
`Resetting ${chalk.bold(`${serviceName}@${stageName}`)}`,
)
await this.client.reset(
serviceName,
stageName,
this.definition.getToken(serviceName, stageName),
)
this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
}
示例4: executeQuery
async executeQuery(
filePath: string,
serviceName: string,
stageName: string,
token?: string,
workspaceSlug?: string,
) {
if (!fs.pathExistsSync(filePath)) {
throw new Error(`Can't find seed import file ${filePath}`)
}
const query = fs.readFileSync(filePath, 'utf-8')
try {
parse(query)
} catch (e) {
throw new Error(`Error while parsing ${filePath}:\n${e.message}`)
}
await this.client.exec(serviceName, stageName, query, token, workspaceSlug)
}
示例5: upload
async upload(
serviceName: string,
stage: string,
token?: string,
workspaceSlug?: string,
) {
try {
if (!this.isDir) {
this.unzip()
}
let before = Date.now()
this.out.action.start('Validating data')
const files = await this.getFiles()
this.validateFiles(files)
this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
before = Date.now()
this.out.log('\nUploading nodes...')
const state = this.getState()
for (const fileName of files.nodes) {
const n = this.getNumber(fileName)
if (state.nodes >= n) {
this.out.log(`Skipping file ${fileName} (already imported)`)
continue
}
const file = fs.readFileSync(fileName, 'utf-8')
const json = JSON.parse(file)
const result = await this.client.upload(
serviceName,
stage,
file,
token,
workspaceSlug,
)
this.checkForErrors(result)
if (result.length > 0) {
this.out.log(this.out.getStyledJSON(result))
this.out.exit(1)
}
state.nodes = n
this.saveState(state)
}
this.out.log(
'Uploading nodes done ' + chalk.cyan(`${Date.now() - before}ms`),
)
before = Date.now()
this.out.log('\nUploading lists')
for (const fileName of files.lists) {
const n = this.getNumber(fileName)
if (state.lists >= n) {
this.out.log(`Skipping file ${fileName} (already imported)`)
continue
}
const file = fs.readFileSync(fileName, 'utf-8')
const json = JSON.parse(file)
const result = await this.client.upload(
serviceName,
stage,
file,
token,
workspaceSlug,
)
this.checkForErrors(result)
if (result.length > 0) {
this.out.log(this.out.getStyledJSON(result))
this.out.exit(1)
}
state.lists = n
this.saveState(state)
}
this.out.log(
'Uploading lists done ' + chalk.cyan(`${Date.now() - before}ms`),
)
before = Date.now()
this.out.log('\nUploading relations')
for (const fileName of files.relations) {
const n = this.getNumber(fileName)
if (state.relations >= n) {
this.out.log(`Skipping file ${fileName} (already imported)`)
continue
}
const file = fs.readFileSync(fileName, 'utf-8')
const json = JSON.parse(file)
const result = await this.client.upload(
serviceName,
stage,
file,
token,
workspaceSlug,
)
this.checkForErrors(result)
if (result.length > 0) {
this.out.log(this.out.getStyledJSON(result))
this.out.exit(1)
}
state.relations = n
this.saveState(state)
}
this.saveState(defaultState)
//.........這裏部分代碼省略.........