本文整理汇总了TypeScript中db/model/Dataset.Dataset.getRepository方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Dataset.getRepository方法的具体用法?TypeScript Dataset.getRepository怎么用?TypeScript Dataset.getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db/model/Dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.getRepository方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: syncDatasetToGitRepo
export async function syncDatasetToGitRepo(datasetId: number, options: { transaction?: db.TransactionContext, oldDatasetName?: string, commitName?: string, commitEmail?: string, commitOnly?: boolean } = {}) {
const { oldDatasetName, commitName, commitEmail, commitOnly } = options
const oldDatasetFilename = oldDatasetName ? filenamify(oldDatasetName) : undefined
const datasetRepo = options.transaction ? options.transaction.manager.getRepository(Dataset) : Dataset.getRepository()
const dataset = await datasetRepo.findOne({ id: datasetId })
if (!dataset) {
throw new JsonError(`No such dataset ${datasetId}`, 404)
}
if (dataset.isPrivate) {
// Private dataset doesn't go in git repo
return removeDatasetFromGitRepo(oldDatasetName||dataset.name, dataset.namespace, options)
}
// Not doing bulk imports for now
if (dataset.namespace !== 'owid')
return
// Base repository directory for this dataspace
const repoDir = path.join(GIT_DATASETS_DIR, dataset.namespace)
if (!fs.existsSync(path.join(repoDir, '.git'))) {
await fs.mkdirp(repoDir)
await execFormatted(`cd %s && git init && git config user.name %s && git config user.email %s`, [repoDir, GIT_DEFAULT_USERNAME, GIT_DEFAULT_EMAIL])
}
// Output dataset to temporary directory
const tmpDatasetDir = path.join(TMP_DIR, dataset.filename)
await fs.mkdirp(tmpDatasetDir)
await Promise.all([
fs.writeFile(path.join(tmpDatasetDir, `${dataset.filename}.csv`), await dataset.toCSV()),
fs.writeFile(path.join(tmpDatasetDir, `datapackage.json`), JSON.stringify(await dataset.toDatapackage(), null, 2)),
fs.writeFile(path.join(tmpDatasetDir, `README.md`), await datasetToReadme(dataset))
])
const datasetsDir = path.join(repoDir, "datasets")
await fs.mkdirp(datasetsDir)
const finalDatasetDir = path.join(datasetsDir, dataset.filename)
const isNew = !fs.existsSync(finalDatasetDir)
await execFormatted(`cd %s && rm -rf %s && mv %s %s && git add -A %s`, [repoDir, finalDatasetDir, tmpDatasetDir, finalDatasetDir, finalDatasetDir])
if (oldDatasetFilename && oldDatasetFilename !== dataset.filename) {
const oldDatasetDir = path.join(datasetsDir, oldDatasetFilename)
await execFormatted(`cd %s && rm -rf %s && git add -A %s`, [repoDir, oldDatasetDir, oldDatasetDir])
}
const commitMsg = isNew ? `Adding ${dataset.filename}` : `Updating ${dataset.filename}`
await execFormatted(`cd %s && (git diff-index --quiet HEAD || (git commit -m %s --quiet --author="${commitName||GIT_DEFAULT_USERNAME} <${commitEmail||GIT_DEFAULT_EMAIL}>"${commitOnly ? "" : " && git push))"}`, [repoDir, commitMsg])
}