Skip to content

doytowin/goooqo-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License

Demo for GoooQo

Introduction

This repo shows how to use GoooQo to access a single table.

The test.db is a database of sqlite which contains a simple table t_user with 4 rows.

id username email nickname memo valid
1 f0rb f0rb@163.com test1 true
2 user2 test2@qq.com test2 false
3 user3 test3@qq.com test3 memo true
4 user4 test4@qq.com test4 true

With GoooQo, we only need to define the structs UserEntity and UserQuery in user.go, where UserEntity corresponds to the table t_user and UserQuery is used to build the query clause. The goooqo.PageQuery embedded in UserQuery helps to implement sorting and paging operations.

Then we build the web APIs listened on http://localhost:9090/user/ by the following two lines:

userDataAccess := rdb.NewTxDataAccess[UserEntity](tm)
goooqo.BuildRestService[UserEntity, UserQuery]("/user/", userDataAccess)

Run the main method in demo.go and visit the the following URLs to check the response:

And there are also some sample POST/PUT/PATCH/DELETE operations listed in user.http to take a try.

NOTE:The web module of GoooQo is for tests and demos only, not a core feature.

License

This project is under the Apache Licence v2.