代码拉取完成,页面将自动刷新
package orm
import (
"context"
"database/sql"
"gitee.com/mosache/YFrame/orm/internal/valuer"
"gitee.com/mosache/YFrame/orm/schema"
)
type core struct {
r *schema.Register
creator valuer.Creator
dialect Dialect
quoter string
mdls []Middleware
//schema *schema.Schema // model
}
func get[T any](ctx context.Context, sess session, c core, qc *QueryContext) *QueryResult {
var err error
qc.schema, err = c.r.Get(new(T))
if err != nil {
return &QueryResult{Err: err}
}
var root Handler = func(ctx context.Context, qc *QueryContext) *QueryResult {
return getHandler[T](ctx, sess, c, qc)
}
for i := len(c.mdls) - 1; i >= 0; i-- {
root = c.mdls[i](root)
}
return root(ctx, qc)
}
func getHandler[T any](ctx context.Context, sess session, c core, qc *QueryContext) *QueryResult {
q, err := qc.Builder.Build()
if err != nil {
return &QueryResult{
Err: err,
}
}
var rows *sql.Rows
if rows, err = sess.queryContext(ctx, q.SQL, q.Args...); err != nil {
return &QueryResult{
Err: err,
}
}
///// 确认有没有数据
for !rows.Next() {
return &QueryResult{
Err: ErrNoRows,
}
}
result := new(T)
valuer := c.creator(qc.schema, result)
if err = valuer.SetColumn(rows); err != nil {
return &QueryResult{
Err: err,
}
}
return &QueryResult{
Result: result,
}
}
func exec(ctx context.Context, sess session, c core, qc *QueryContext) *QueryResult {
var root Handler = func(ctx context.Context, qc *QueryContext) *QueryResult {
return execHandler(ctx, sess, qc)
}
for idx := len(c.mdls) - 1; idx >= 0; idx-- {
root = c.mdls[idx](root)
}
return root(ctx, qc)
}
func execHandler(ctx context.Context, sess session, qc *QueryContext) *QueryResult {
var (
q *Query
sqlResult sql.Result
err error
)
q, err = qc.Builder.Build()
if err != nil {
return &QueryResult{
Err: err,
}
}
sqlResult, err = sess.execContext(ctx, q.SQL, q.Args...)
if err != nil {
return &QueryResult{
Err: err,
}
}
return &QueryResult{Result: sqlResult}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。