路由: routes
Route.get('/hello', ({ request }) => {
return `hello ~ ${ request.input('name') }`
})
控制器:Controllers
adonis make:controller Hello
create app/Controllers/Http/HelloController.js
http://127.0.0.1:3333/hello?name=boloog
視圖:Views
adonis make:view hello
? create resources/views/hello.edge
數(shù)據(jù)庫:Database
adonis install sqlite3
添加數(shù)據(jù)表
adonis make:migration Post
? create database/migrations/1531930044179_post_schema.js
this.create('posts', (table) => {
table.increments()
table.string('title')
table.text('content', 'longtext')
table.timestamps()
})
- 運行應用的
migration
adonis migration:run
migrate: 1503248427885_user.js
migrate: 1503248427886_token.js
migrate: 1531930044179_post_schema.js
Database migrated successfully in 111 ms
引入數(shù)據(jù)庫:插入與查詢數(shù)據(jù)五嫂,添加路由查看全部內容
const Database = use('Database')
// 查看數(shù)據(jù)表里的所有數(shù)據(jù)
Route.get('/posts', async () => {
return await Database.table('posts').select('*')
})
adonis repl //打開命令交互模式
> await use('Database').table('posts').insert({ title: 'apple', content: '蘋果'})
> await use('Database').table('posts').insert({ title: 'orange', content: '橘子'})
http://127.0.0.1:3333/posts