Browse Source
Upgrade xorm to v1.0.2 (#11900)
Upgrade xorm to v1.0.2 (#11900)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>mj-v1.14.3
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 817 additions and 763 deletions
-
2go.mod
-
4go.sum
-
2models/context.go
-
2vendor/modules.txt
-
9vendor/xorm.io/xorm/.drone.yml
-
2vendor/xorm.io/xorm/.gitignore
-
50vendor/xorm.io/xorm/Makefile
-
4vendor/xorm.io/xorm/README.md
-
75vendor/xorm.io/xorm/contexts/hook.go
-
57vendor/xorm.io/xorm/convert.go
-
79vendor/xorm.io/xorm/core/db.go
-
78vendor/xorm.io/xorm/core/stmt.go
-
95vendor/xorm.io/xorm/core/tx.go
-
112vendor/xorm.io/xorm/dialects/dialect.go
-
13vendor/xorm.io/xorm/dialects/mssql.go
-
20vendor/xorm.io/xorm/dialects/mysql.go
-
9vendor/xorm.io/xorm/dialects/oracle.go
-
13vendor/xorm.io/xorm/dialects/postgres.go
-
13vendor/xorm.io/xorm/dialects/sqlite3.go
-
2vendor/xorm.io/xorm/doc.go
-
145vendor/xorm.io/xorm/engine.go
-
11vendor/xorm.io/xorm/engine_group.go
-
2vendor/xorm.io/xorm/engine_group_policy.go
-
2vendor/xorm.io/xorm/error.go
-
2vendor/xorm.io/xorm/interface.go
-
108vendor/xorm.io/xorm/internal/statements/insert.go
-
23vendor/xorm.io/xorm/internal/statements/pk.go
-
3vendor/xorm.io/xorm/internal/statements/statement.go
-
32vendor/xorm.io/xorm/internal/statements/statement_args.go
-
3vendor/xorm.io/xorm/internal/statements/update.go
-
2vendor/xorm.io/xorm/internal/statements/values.go
-
42vendor/xorm.io/xorm/log/logger_context.go
-
35vendor/xorm.io/xorm/names/mapper.go
-
66vendor/xorm.io/xorm/processors.go
-
16vendor/xorm.io/xorm/schemas/column.go
-
49vendor/xorm.io/xorm/schemas/table.go
-
192vendor/xorm.io/xorm/session.go
-
6vendor/xorm.io/xorm/session_delete.go
-
20vendor/xorm.io/xorm/session_find.go
-
2vendor/xorm.io/xorm/session_get.go
-
96vendor/xorm.io/xorm/session_insert.go
-
1vendor/xorm.io/xorm/tags/parser.go
-
81vendor/xorm.io/xorm/xorm.go
@ -0,0 +1,75 @@ |
|||
// Copyright 2020 The Xorm Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style
|
|||
// license that can be found in the LICENSE file.
|
|||
|
|||
package contexts |
|||
|
|||
import ( |
|||
"context" |
|||
"database/sql" |
|||
"time" |
|||
) |
|||
|
|||
// ContextHook represents a hook context
|
|||
type ContextHook struct { |
|||
start time.Time |
|||
Ctx context.Context |
|||
SQL string // log content or SQL
|
|||
Args []interface{} // if it's a SQL, it's the arguments
|
|||
Result sql.Result |
|||
ExecuteTime time.Duration |
|||
Err error // SQL executed error
|
|||
} |
|||
|
|||
// NewContextHook return context for hook
|
|||
func NewContextHook(ctx context.Context, sql string, args []interface{}) *ContextHook { |
|||
return &ContextHook{ |
|||
start: time.Now(), |
|||
Ctx: ctx, |
|||
SQL: sql, |
|||
Args: args, |
|||
} |
|||
} |
|||
|
|||
func (c *ContextHook) End(ctx context.Context, result sql.Result, err error) { |
|||
c.Ctx = ctx |
|||
c.Result = result |
|||
c.Err = err |
|||
c.ExecuteTime = time.Now().Sub(c.start) |
|||
} |
|||
|
|||
type Hook interface { |
|||
BeforeProcess(c *ContextHook) (context.Context, error) |
|||
AfterProcess(c *ContextHook) error |
|||
} |
|||
|
|||
type Hooks struct { |
|||
hooks []Hook |
|||
} |
|||
|
|||
func (h *Hooks) AddHook(hooks ...Hook) { |
|||
h.hooks = append(h.hooks, hooks...) |
|||
} |
|||
|
|||
func (h *Hooks) BeforeProcess(c *ContextHook) (context.Context, error) { |
|||
ctx := c.Ctx |
|||
for _, h := range h.hooks { |
|||
var err error |
|||
ctx, err = h.BeforeProcess(c) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
} |
|||
return ctx, nil |
|||
} |
|||
|
|||
func (h *Hooks) AfterProcess(c *ContextHook) error { |
|||
firstErr := c.Err |
|||
for _, h := range h.hooks { |
|||
err := h.AfterProcess(c) |
|||
if err != nil && firstErr == nil { |
|||
firstErr = err |
|||
} |
|||
} |
|||
return firstErr |
|||
} |