This file contains 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
// All users | |
await Database.from('users').select('*') | |
// Get admin users | |
await Database.from('users').where('role', 'admin') | |
// Inactive users | |
await Database | |
.from('users') | |
.where('status', 'inactive') |
This file contains 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
await Database | |
.table('users') | |
.insert({ username: 'virk', role: 'admin', password: 'secret' }) | |
// Bulk inserts | |
await Database | |
.table('users') | |
.insert([ | |
{ username: 'virk', role: 'admin', password: 'secret' }, | |
{ username: 'nikk', role: 'guest', password: 'secret' } |
This file contains 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 |
This file contains 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
const Model = use('Model') | |
class User extends Model { | |
} | |
class Post extends Model { | |
} | |
class Category extends Model { | |
} |
This file contains 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
const Model = use('Model') | |
class User extends Model { | |
posts () { | |
return this.hasMany('App/Models/Post') | |
} | |
} | |
class Post extends Model { | |
author () { |
This file contains 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
// Import category model | |
const Category = use('App/Models/Category') | |
// Get all categories | |
const categories = await Category.all() |
This file contains 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
function rext () { | |
if [ $# -lt 3 ]; then | |
echo 1>&2 "$0 needs 3 arguments as DIR SOURCE_EXT DEST_EXT" | |
else | |
for file in "$1"/*.$2; do | |
mv "$file" "${file%.$2}.$3" | |
done | |
fi | |
} |
This file contains 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
const { registrar, ioc } = require('@adonisjs/fold') | |
const _ = require('lodash') | |
/** | |
* Very bare bones implementation of the config provider. | |
* If you run into issues, then make sure to check the | |
* implementation in adonis-framework repo | |
*/ | |
class Config { | |
constructor (config) { |
This file contains 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
const { hooks } = require('@adonisjs/ignitor') | |
hooks.after.httpServer(function () { | |
const Server = use('Server') | |
const httpInstance = Server.getInstance() | |
// do whatever you like | |
}) |
This file contains 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
"editor.tokenColorCustomizations": { | |
"textMateRules": [ | |
{ | |
"scope": "storage.type.class.jsdoc, punctuation.definition.block.tag.jsdoc, punctuation.definition.bracket.curly.begin.jsdoc, punctuation.definition.bracket.curly.end.jsdoc,variable.other.jsdoc", | |
"settings": { | |
"foreground": "#65737eff", | |
} | |
} | |
] | |
} |