Generate Model
If you use Model like Objection.js to you can generate Objection model by
napim make:model ModelName
if you prefer to use raw query, just import {db} from "napim"
and use it like db.query(trx)... see knex documentation for detail
If you want to use db transaction, just change transaction to true in your service file, ez
You like NoSQL like mongo, just edit your .env add DB_DRIVER=mongo
and create your own Model or Schema and import to your service like usually
TODO: implement db transaction for mongo
Generate Middleware
Want to make Auth, JWT, or handle uploaded file (eg: using multer) you can create it in middleware
napim make:middleware JWT
then use it in router, append it in middleware array for example:
//router.json
[
{
"tag": "default",
"prefix": "/api",
"middleware": [],
"get": [],
"post": [
{
"path": "/login",
"service": "/login_post"
}
]
},
{
"tag": "secure",
"prefix": "/api/secure",
"middleware": [
"JWT"
],
"get": [
{
"path": "/products/:id",
"service": "/products/_id_get"
}
]
},
{
"tag": "admin",
"prefix": "/api/admin",
"middleware": [
"JWT",
"Admin"
],
"get": [
{
"path": "/products",
"service": "/products_get"
}
],
"post": [
{
"path": "/products",
"service": "/products_post"
}
],
"delete": [
{
"path": "/products/:id",
"service": "/producst/_id_delete"
}
],
"patch": [
{
"path": "/products/:id",
"service": "/producst/_id_patch"
}
]
}
]
Polka App Instance
If you want to access polka instance, just import {app} from "napim"