• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript db.end函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中db/db.end函数的典型用法代码示例。如果您正苦于以下问题:TypeScript end函数的具体用法?TypeScript end怎么用?TypeScript end使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了end函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: dataExport

async function dataExport() {
    await db.connect()

    const tmpFile = "/tmp/owid_chartdata.sql"

    const variablesToExportQuery = `
        SELECT DISTINCT cd.variableId FROM chart_dimensions cd
        WHERE NOT EXISTS (select * from tags t join chart_tags ct on ct.tagId = t.id where ct.chartId=cd.chartId and t.name='Private')
    `

    const variableIds = (await db.query(variablesToExportQuery)).map((row: any) => row.variableId)

    console.log(`Exporting data for ${variableIds.length} variables to ${tmpFile}`)

    await exec(`rm -f ${tmpFile}`)

    let count = 0
    for (const chunk of _.chunk(variableIds, 100)) {
        await exec(`mysqldump --no-create-info ${DB_NAME} data_values --where="variableId IN (${chunk.join(",")})" >> ${tmpFile}`)

        count += chunk.length
        console.log(count)
    }

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:26,代码来源:exportChartData.ts


示例2: main

async function main() {
    try {
        await syncPostsToGrapher()
    } finally {
        await wpdb.end()
        await db.end()
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:8,代码来源:syncPostsToGrapher.ts


示例3: 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


示例4: main

async function main() {
    await db.connect()
    try {
//    await importCodebook()
        await importData()
    } finally {
        await db.end()
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:9,代码来源:importVDemDataset.ts


示例5: dataExport

async function dataExport() {
    await db.connect()

    const slugs = (await fs.readFile("/Users/mispy/tmp/urls.txt", "utf8")).split("\n").filter(s => s.trim())
    const slugToId = await Chart.mapSlugsToIds()
    const idsToGet = slugs.map(slug => slugToId[slug])

    const variables = await db.query("SELECT v.name, v.id FROM variables v JOIN chart_dimensions cd ON cd.variableId=v.id WHERE cd.chartId IN (?)", [idsToGet])
    const variableIds = variables.map((v: any) => v.id)
    const stream = fs.createWriteStream("/Users/mispy/tmp/sdgs.csv")

    // From dataset CSV export
    const csvHeader = ["Entity", "Year"]
    for (const variable of variables) {
        csvHeader.push(variable.name)
    }

    const columnIndexByVariableId: {[key: number]: number} = {}
    for (const variable of variables) {
        columnIndexByVariableId[variable.id] = csvHeader.indexOf(variable.name)
    }

    stream.write(csvRow(csvHeader))

    const data = await db.query(`
        SELECT e.name AS entity, dv.year, dv.value, dv.variableId FROM data_values dv
        JOIN variables v ON v.id=dv.variableId
        JOIN entities e ON dv.entityId=e.id
        WHERE v.id IN (?)
        ORDER BY e.name ASC, dv.year ASC, dv.variableId ASC`, [variableIds])

    let row: string[] = []
    for (const datum of data) {
        if (datum.entity !== row[0] || datum.year !== row[1]) {
            // New row
            if (row.length) {
                stream.write(csvRow(row))
            }
            row = [datum.entity, datum.year]
            for (const variable of variables) {
                row.push("")
            }
        }

        row[columnIndexByVariableId[datum.variableId]] = datum.value
    }

    // Final row
    stream.write(csvRow(row))

    stream.end()

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:54,代码来源:exportSDGTrackerData.ts


示例6: dataExport

async function dataExport() {
    await db.connect()

    console.log(`Exporting database structure and metadata to /tmp/owid_metadata.sql...`)

    // Dump all tables including schema but exclude the rows of data_values
    await exec(`mysqldump ${DB_NAME} --ignore-table=${DB_NAME}.sessions --ignore-table=${DB_NAME}.user_invitations --ignore-table=${DB_NAME}.data_values -r /tmp/owid_metadata.sql`)
    await exec(`mysqldump --no-data ${DB_NAME} sessions user_invitations data_values >> /tmp/owid_metadata.sql`)

    // Strip passwords
    await exec(`sed -i -e "s/bcrypt[^']*//g" /tmp/owid_metadata.sql`)

    // Add default admin user
    await fs.appendFile("/tmp/owid_metadata.sql", "INSERT INTO users (`password`, `isSuperuser`, `email`, `fullName`, `createdAt`, `updatedAt`, `isActive`) VALUES ('bcrypt$$2b$12$EXfM7cWsjlNchpinv.j6KuOwK92hihg5r3fNssty8tLCUpOubST9u', 1, '[email protected]', 'Admin User', '2016-01-01 00:00:00', '2016-01-01 00:00:00', 1);\n")

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:17,代码来源:exportMetadata.ts


示例7: main

async function main(email: string, name: string, postId: number, postSlug: string) {
    try {
        console.log(email, name, postId)
        const slug = await syncPostToGrapher(postId)

        if (BAKE_ON_CHANGE) {
            const baker = new SiteBaker({})
            await baker.bakeAll()
            await baker.deploy(slug ? `Updating ${slug}` : `Deleting ${postSlug}`, email, name)
            baker.end()
        }
    } catch (err) {
        log.error(err)
    } finally {
        await wpdb.end()
        await db.end()
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:18,代码来源:postUpdatedHook.ts


示例8: main

async function main(target: string, isPreview?: boolean) {
    try {
        if (target === 'front') {
            console.log(await renderFrontPage())
        } else if (target === 'subscribe') {
            console.log(await renderSubscribePage())
        } else if (target === "blog") {
            const pageNum = process.argv[3] ? parseInt(process.argv[3]) : 1
            console.log(await renderBlogByPageNum(pageNum === 0 ? 1 : pageNum))
        } else {
            console.log(await renderPageById(parseInt(target), isPreview))
        }
    } catch (err) {
        console.error(err)
    } finally {
        wpdb.end()
        db.end()
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:19,代码来源:renderPage.ts


示例9: main

async function main() {
    try {
        const categoriesByPostId = await wpdb.getCategoriesByPostId()

        const tagsByPostId = await wpdb.getTagsByPostId()
        const postRows = await wpdb.query("select * from wp_posts where (post_type='page' or post_type='post') AND post_status != 'trash'")
    
        for (const post of postRows) {
            const categories = categoriesByPostId.get(post.ID)||[]

            let tagNames = categories.map(t => decodeHTML(t))

            const matchingTags = await Tag.select('id', 'name', 'isBulkImport').from(
                db.table(Tag.table).whereIn('name', tagNames).andWhere({ isBulkImport: false })
            )

            const existingTags = await Tag.select('id').from(
                db.table(Tag.table)
                    .join('post_tags', { 'post_tags.tag_id': 'tags.id' })
                    .where({ 'post_tags.post_id': post.ID })
            )

            const tagIds = matchingTags.map(t => t.id).concat(existingTags.map(t => t.id))
            // if (matchingTags.map(t => t.name).includes(post.post_title)) {
            //     tagIds.push(1640)
            // }


            // const matchingTags = await Tag.select('id', 'name', 'isBulkImport').from(
            //     db.knex().from(Tag.table).whereIn('name', tagNames).andWhere({ isBulkImport: false })
            // )
            // let tagIds = matchingTags.map(t => t.id)
            // if (matchingTags.map(t => t.name).includes(post.post_title)) {
            //     tagIds.push(1640)
            // }
            await Post.setTags(post.ID, _.uniq(tagIds))
        }
    } finally {
        await wpdb.end()
        await db.end()
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:42,代码来源:postCategoriesToGrapher.ts


示例10: dataExport

async function dataExport() {
    await db.connect()

    const tmpFilename: string = `/tmp/owid_chartdata_${namespaces.join(",")}.sql`

    // This will also retrieve variables that are not in the specified namespace
    // but are used in a chart that has at least one variable from the specified
    // namespace.
    // This is necessary in order to reproduce the charts from the live grapher
    // accurately.
    const rows = await db.query(`
        SELECT DISTINCT chart_dimensions.variableId
        FROM chart_dimensions
        WHERE chart_dimensions.chartId IN (
            SELECT DISTINCT charts.id
            FROM charts
            JOIN chart_dimensions ON chart_dimensions.chartId = charts.id
            JOIN variables ON variables.id = chart_dimensions.variableId
            JOIN datasets ON datasets.id = variables.datasetId
            WHERE datasets.namespace IN (?)
        )
    `, [namespaces])

    const variableIds = rows.map((row: any) => row.variableId)

    console.log(`Exporting data for ${variableIds.length} variables to ${tmpFilename}`)

    await exec(`rm -f ${tmpFilename}`)

    let count = 0
    for (const chunk of _.chunk(variableIds, 100)) {
        await exec(`mysqldump --no-create-info ${DB_NAME} data_values --where="variableId IN (${chunk.join(",")})" >> ${tmpFilename}`)

        count += chunk.length
        console.log(count)
    }

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:39,代码来源:exportChartDataNamespace.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript db.execute函数代码示例发布时间:2022-05-25
下一篇:
TypeScript db.connect函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap