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


TypeScript wpdb.end函数代码示例

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


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

示例1: main

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

示例2: undoPermalinks

async function undoPermalinks() {
    const rows = await wpdb.query(`SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key='custom_permalink'`)

    for (const row of rows) {
        await wpdb.query(`UPDATE wp_posts SET post_name = ? WHERE ID=?`, [row.meta_value.replace(/\/+$/g, "").replace(/\//g, "__").replace(/--/g, "__"), row.post_id])
    }

    wpdb.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:9,代码来源:underscorePermalinks.ts

示例3: getTitles

async function getTitles() {
    await wpdb.connect()

    const pageRows = await wpdb.query(`
        SELECT post_title FROM wp_posts AS posts
        WHERE (posts.post_type='page' OR posts.post_type='post') AND posts.post_status='publish' ORDER BY post_title DESC
    `)

    await wpdb.end()

    return pageRows.map(row => asciify(row.post_title))
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:12,代码来源:googleTrendsAnalysis.ts

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

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

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

示例7: indexToAlgolia

async function indexToAlgolia() {
    const client = algoliasearch(ALGOLIA_ID, ALGOLIA_SECRET_KEY)
    const finalIndex = await client.initIndex('pages')
    const tmpIndex = await client.initIndex('pages_tmp')

    // Copy to a temporary index which we will then update
    // This is so we can do idempotent reindexing
    await client.copyIndex(finalIndex.indexName, tmpIndex.indexName, [
        'settings',
        'synonyms',
        'rules'
    ])

    const rows = await wpdb.query(`SELECT * FROM wp_posts WHERE (post_type='post' OR post_type='page') AND post_status='publish'`)

    const records = []

    for (const country of countries) {
        records.push({
            objectID: country.slug,
            type: 'country',
            slug: country.slug,
            title: country.name,
            content: `All available indicators for ${country.name}.`
        })
    }

    for (const row of rows) {
        const rawPost = await wpdb.getFullPost(row)
        const post = await formatPost(rawPost, { footnotes: false })
        const postText = htmlToPlaintext(post.html)
        const chunks = chunkParagraphs(postText, 1000)

        const tags = await getPostTags(post.id)
        const postType = getPostType(post, tags)

        let importance = 0
        if (postType === 'entry')
            importance = 3
        else if (postType === 'explainer')
            importance = 2
        else if (postType === 'fact')
            importance = 1

        let i = 0
        for (const c of chunks) {
            records.push({
                objectID: `${row.ID}-c${i}`,
                postId: post.id,
                type: postType,
                slug: post.slug,
                title: post.title,
                excerpt: post.excerpt,
                authors: post.authors,
                date: post.date,
                modifiedDate: post.modifiedDate,
                content: c,
                _tags: tags.map(t => t.name),
                importance: importance
            })
            i += 1
        }
    }


    for (let i = 0; i < records.length; i += 1000) {
        await tmpIndex.saveObjects(records.slice(i, i+1000))
    }
    await client.moveIndex(tmpIndex.indexName, finalIndex.indexName);

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


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