Skip to content

Instantly share code, notes, and snippets.

@thetutlage
Created June 27, 2018 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetutlage/498306ccd5774831fbd13382c625c053 to your computer and use it in GitHub Desktop.
Save thetutlage/498306ccd5774831fbd13382c625c053 to your computer and use it in GitHub Desktop.
AdonisJs blog queries via query builder
// 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