Created
June 27, 2018 09:43
-
-
Save thetutlage/498306ccd5774831fbd13382c625c053 to your computer and use it in GitHub Desktop.
AdonisJs blog queries via query builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Display categories in the blog header | |
const categories = await Database.table('categories').select('*') | |
// Fetch posts for a category where category_id = 1 | |
const posts = await Database | |
.table('posts') | |
.innerJoin('category_posts', 'posts.id', 'category_posts.post_id') | |
.where('category_posts.category_id', categoryId) | |
// Select author for a given post | |
const author = await Database | |
.table('users') | |
.where('id', post.user_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment