本文整理汇总了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 }
})
示例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()
}
示例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])
}