当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Dataset.getRepository方法代码示例

本文整理汇总了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])
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:54,代码来源:gitDataExport.ts


注:本文中的db/model/Dataset.Dataset.getRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。