本文整理汇总了TypeScript中db/model/Dataset.Dataset类的典型用法代码示例。如果您正苦于以下问题:TypeScript Dataset类的具体用法?TypeScript Dataset怎么用?TypeScript Dataset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dataset类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: async
api.post('/datasets/:datasetId/setTags', async (req: Request, res: Response) => {
const datasetId = expectInt(req.params.datasetId)
await Dataset.setTags(datasetId, req.body.tagIds)
return { success: true }
})
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:7,代码来源:api.ts
示例2: main
async function main() {
await db.connect()
for (const dataset of await Dataset.find({ namespace: 'owid' })) {
if (!dataset.isPrivate)
await syncDatasetToGitRepo(dataset.id, { commitOnly: true })
}
await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:8,代码来源:exportGitData.ts
示例3: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论