本文整理汇总了TypeScript中db/model/Post.Post.select方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Post.select方法的具体用法?TypeScript Post.select怎么用?TypeScript Post.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db/model/Post.Post
的用法示例。
在下文中一共展示了Post.select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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)) }
})