本文整理汇总了TypeScript中db/model/Post.Post类的典型用法代码示例。如果您正苦于以下问题:TypeScript Post类的具体用法?TypeScript Post怎么用?TypeScript Post使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
api.post('/posts/:postId/setTags', async (req: Request, res: Response) => {
const postId = expectInt(req.params.postId)
await Post.setTags(postId, req.body.tagIds)
return { success: true }
})
示例2: getBlogIndex
export async function getBlogIndex(): Promise<PostInfo[]> {
if (cachedPosts) return cachedPosts
const rows = await wpdb.query(`
SELECT ID, post_title, post_date, post_name FROM wp_posts
WHERE post_status='publish' AND post_type='post' ORDER BY post_date DESC
`)
const permalinks = await getPermalinks()
const authorship = await getAuthorship()
const featuredImages = await getFeaturedImages()
const tagsByPostId = await Post.tagsByPostId()
cachedPosts = rows.map(row => {
return {
title: row.post_title,
date: new Date(row.post_date),
slug: permalinks.get(row.ID, row.post_name),
authors: authorship.get(row.ID)||[],
imageUrl: featuredImages.get(row.ID),
tags: tagsByPostId.get(row.ID)||[]
}
})
return cachedPosts
}
示例3: camelCaseProperties
api.get('/posts.json', async req => {
const rows = await Post.select('id', 'title', 'type', 'status', 'updated_at').from(db.knex().from(Post.table).orderBy('updated_at', 'desc'))
const tagsByPostId = await Post.tagsByPostId()
// const rows = await wpdb.query(`
// SELECT ID AS id, post_title AS title, post_modified_gmt AS updatedAt, post_type AS type, post_status AS status
// FROM wp_posts
// WHERE (post_type='post' OR post_type='page')
// AND (post_status='publish' OR post_status='pending' OR post_status='private' OR post_status='draft')
// ORDER BY post_modified DESC`)
const authorship = await wpdb.getAuthorship()
for (const post of rows) {
(post as any).authors = authorship.get(post.id)||[];
(post as any).tags = tagsByPostId.get(post.id)||[]
}
return { posts: rows.map(r => camelCaseProperties(r)) }
})
示例4: 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()
}
}