go get -u github.com/doytowin/goooqo
package main
import (
"database/sql"
"github.com/doytowin/goooqo/rdb"
_ "github.com/mattn/go-sqlite3"
)
func main() {
db, _ := sql.Open("sqlite3", "./test.db")
tm := rdb.NewTransactionManager(db)
//...
}
package main
import (
. "github.com/doytowin/goooqo"
)
type UserEntity struct {
Int64Id
Name *string `json:"name"`
Score *int `json:"score"`
Memo *string `json:"memo"`
}
func (u UserEntity) GetTableName() string {
return "t_user"
}
type UserQuery struct {
PageQuery
ScoreLt *int
MemoStart *string
// ...
}
userDataAccess := rdb.NewTxDataAccess[UserEntity](tm)
userQuery := UserQuery{PageQuery: PageQuery{PageSize: P(10)}, ScoreLt: P(80)}
userEntities, err := userDataAccess.Query(ctx, userQuery)
SELECT id, name, score, memo FROM t_user WHERE score < ? LIMIT 10 OFFSET 0