Skip to content

Commit bd9535d

Browse files
committed
Fix comments (#1893)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1893 Co-authored-by: Lunny Xiao <[email protected]> Co-committed-by: Lunny Xiao <[email protected]>
1 parent 1ade496 commit bd9535d

File tree

10 files changed

+76
-12
lines changed

10 files changed

+76
-12
lines changed

.revive.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ warningCode = 1
1515
[rule.if-return]
1616
[rule.increment-decrement]
1717
[rule.var-naming]
18+
arguments = [["ID", "UID", "UUID", "URL", "JSON"], []]
1819
[rule.var-declaration]
1920
[rule.package-comments]
2021
[rule.range]
2122
[rule.receiver-naming]
2223
[rule.time-naming]
2324
[rule.unexported-return]
2425
[rule.indent-error-flow]
25-
[rule.errorf]
26+
[rule.errorf]
27+
[rule.struct-tag]

caches/encode.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@ import (
1313
"io"
1414
)
1515

16-
// md5 hash string
16+
// Md5 return md5 hash string
1717
func Md5(str string) string {
1818
m := md5.New()
1919
io.WriteString(m, str)
2020
return fmt.Sprintf("%x", m.Sum(nil))
2121
}
22+
23+
// Encode Encode data
2224
func Encode(data interface{}) ([]byte, error) {
2325
//return JsonEncode(data)
2426
return GobEncode(data)
2527
}
2628

29+
// Decode decode data
2730
func Decode(data []byte, to interface{}) error {
2831
//return JsonDecode(data, to)
2932
return GobDecode(data, to)
3033
}
3134

35+
// GobEncode encode data with gob
3236
func GobEncode(data interface{}) ([]byte, error) {
3337
var buf bytes.Buffer
3438
enc := gob.NewEncoder(&buf)
@@ -39,12 +43,14 @@ func GobEncode(data interface{}) ([]byte, error) {
3943
return buf.Bytes(), nil
4044
}
4145

46+
// GobDecode decode data with gob
4247
func GobDecode(data []byte, to interface{}) error {
4348
buf := bytes.NewBuffer(data)
4449
dec := gob.NewDecoder(buf)
4550
return dec.Decode(to)
4651
}
4752

53+
// JsonEncode encode data with json
4854
func JsonEncode(data interface{}) ([]byte, error) {
4955
val, err := json.Marshal(data)
5056
if err != nil {
@@ -53,6 +59,7 @@ func JsonEncode(data interface{}) ([]byte, error) {
5359
return val, nil
5460
}
5561

62+
// JsonDecode decode data with json
5663
func JsonDecode(data []byte, to interface{}) error {
5764
return json.Unmarshal(data, to)
5865
}

core/tx.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Tx struct {
2222
ctx context.Context
2323
}
2424

25+
// BeginTx begin a transaction with option
2526
func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
2627
hookCtx := contexts.NewContextHook(ctx, "BEGIN TRANSACTION", nil)
2728
ctx, err := db.beforeProcess(hookCtx)
@@ -36,10 +37,12 @@ func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
3637
return &Tx{tx, db, ctx}, nil
3738
}
3839

40+
// Begin begins a transaction
3941
func (db *DB) Begin() (*Tx, error) {
4042
return db.BeginTx(context.Background(), nil)
4143
}
4244

45+
// Commit submit the transaction
4346
func (tx *Tx) Commit() error {
4447
hookCtx := contexts.NewContextHook(tx.ctx, "COMMIT", nil)
4548
ctx, err := tx.db.beforeProcess(hookCtx)
@@ -54,6 +57,7 @@ func (tx *Tx) Commit() error {
5457
return nil
5558
}
5659

60+
// Rollback rollback the transaction
5761
func (tx *Tx) Rollback() error {
5862
hookCtx := contexts.NewContextHook(tx.ctx, "ROLLBACK", nil)
5963
ctx, err := tx.db.beforeProcess(hookCtx)
@@ -68,6 +72,7 @@ func (tx *Tx) Rollback() error {
6872
return nil
6973
}
7074

75+
// PrepareContext prepare the query
7176
func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error) {
7277
names := make(map[string]int)
7378
var i int
@@ -89,19 +94,23 @@ func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error) {
8994
return &Stmt{stmt, tx.db, names, query}, nil
9095
}
9196

97+
// Prepare prepare the query
9298
func (tx *Tx) Prepare(query string) (*Stmt, error) {
9399
return tx.PrepareContext(context.Background(), query)
94100
}
95101

102+
// StmtContext creates Stmt with context
96103
func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt {
97104
stmt.Stmt = tx.Tx.StmtContext(ctx, stmt.Stmt)
98105
return stmt
99106
}
100107

108+
// Stmt creates Stmt
101109
func (tx *Tx) Stmt(stmt *Stmt) *Stmt {
102110
return tx.StmtContext(context.Background(), stmt)
103111
}
104112

113+
// ExecMapContext executes query with args in a map
105114
func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) {
106115
query, args, err := MapToSlice(query, mp)
107116
if err != nil {
@@ -110,10 +119,12 @@ func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{})
110119
return tx.ExecContext(ctx, query, args...)
111120
}
112121

122+
// ExecMap executes query with args in a map
113123
func (tx *Tx) ExecMap(query string, mp interface{}) (sql.Result, error) {
114124
return tx.ExecMapContext(context.Background(), query, mp)
115125
}
116126

127+
// ExecStructContext executes query with args in a struct
117128
func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error) {
118129
query, args, err := StructToSlice(query, st)
119130
if err != nil {
@@ -122,6 +133,7 @@ func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{
122133
return tx.ExecContext(ctx, query, args...)
123134
}
124135

136+
// ExecContext executes a query with args
125137
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
126138
hookCtx := contexts.NewContextHook(ctx, query, args)
127139
ctx, err := tx.db.beforeProcess(hookCtx)
@@ -136,10 +148,12 @@ func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}
136148
return res, err
137149
}
138150

151+
// ExecStruct executes query with args in a struct
139152
func (tx *Tx) ExecStruct(query string, st interface{}) (sql.Result, error) {
140153
return tx.ExecStructContext(context.Background(), query, st)
141154
}
142155

156+
// QueryContext query with args
143157
func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
144158
hookCtx := contexts.NewContextHook(ctx, query, args)
145159
ctx, err := tx.db.beforeProcess(hookCtx)
@@ -157,10 +171,12 @@ func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{
157171
return &Rows{rows, tx.db}, nil
158172
}
159173

174+
// Query query with args
160175
func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) {
161176
return tx.QueryContext(context.Background(), query, args...)
162177
}
163178

179+
// QueryMapContext query with args in a map
164180
func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) {
165181
query, args, err := MapToSlice(query, mp)
166182
if err != nil {
@@ -169,10 +185,12 @@ func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{})
169185
return tx.QueryContext(ctx, query, args...)
170186
}
171187

188+
// QueryMap query with args in a map
172189
func (tx *Tx) QueryMap(query string, mp interface{}) (*Rows, error) {
173190
return tx.QueryMapContext(context.Background(), query, mp)
174191
}
175192

193+
// QueryStructContext query with args in struct
176194
func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error) {
177195
query, args, err := StructToSlice(query, st)
178196
if err != nil {
@@ -181,19 +199,23 @@ func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface
181199
return tx.QueryContext(ctx, query, args...)
182200
}
183201

202+
// QueryStruct query with args in struct
184203
func (tx *Tx) QueryStruct(query string, st interface{}) (*Rows, error) {
185204
return tx.QueryStructContext(context.Background(), query, st)
186205
}
187206

207+
// QueryRowContext query one row with args
188208
func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row {
189209
rows, err := tx.QueryContext(ctx, query, args...)
190210
return &Row{rows, err}
191211
}
192212

213+
// QueryRow query one row with args
193214
func (tx *Tx) QueryRow(query string, args ...interface{}) *Row {
194215
return tx.QueryRowContext(context.Background(), query, args...)
195216
}
196217

218+
// QueryRowMapContext query one row with args in a map
197219
func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row {
198220
query, args, err := MapToSlice(query, mp)
199221
if err != nil {
@@ -202,10 +224,12 @@ func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface
202224
return tx.QueryRowContext(ctx, query, args...)
203225
}
204226

227+
// QueryRowMap query one row with args in a map
205228
func (tx *Tx) QueryRowMap(query string, mp interface{}) *Row {
206229
return tx.QueryRowMapContext(context.Background(), query, mp)
207230
}
208231

232+
// QueryRowStructContext query one row with args in struct
209233
func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row {
210234
query, args, err := StructToSlice(query, st)
211235
if err != nil {
@@ -214,6 +238,7 @@ func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interf
214238
return tx.QueryRowContext(ctx, query, args...)
215239
}
216240

241+
// QueryRowStruct query one row with args in struct
217242
func (tx *Tx) QueryRowStruct(query string, st interface{}) *Row {
218243
return tx.QueryRowStructContext(context.Background(), query, st)
219244
}

dialects/driver.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
)
1010

11+
// Driver represents a database driver
1112
type Driver interface {
1213
Parse(string, string) (*URI, error)
1314
}
@@ -16,6 +17,7 @@ var (
1617
drivers = map[string]Driver{}
1718
)
1819

20+
// RegisterDriver register a driver
1921
func RegisterDriver(driverName string, driver Driver) {
2022
if driver == nil {
2123
panic("core: Register driver is nil")
@@ -26,10 +28,12 @@ func RegisterDriver(driverName string, driver Driver) {
2628
drivers[driverName] = driver
2729
}
2830

31+
// QueryDriver query a driver with name
2932
func QueryDriver(driverName string) Driver {
3033
return drivers[driverName]
3134
}
3235

36+
// RegisteredDriverSize returned all drivers's length
3337
func RegisteredDriverSize() int {
3438
return len(drivers)
3539
}
@@ -38,7 +42,7 @@ func RegisteredDriverSize() int {
3842
func OpenDialect(driverName, connstr string) (Dialect, error) {
3943
driver := QueryDriver(driverName)
4044
if driver == nil {
41-
return nil, fmt.Errorf("Unsupported driver name: %v", driverName)
45+
return nil, fmt.Errorf("unsupported driver name: %v", driverName)
4246
}
4347

4448
uri, err := driver.Parse(driverName, connstr)
@@ -48,7 +52,7 @@ func OpenDialect(driverName, connstr string) (Dialect, error) {
4852

4953
dialect := QueryDialect(uri.DBType)
5054
if dialect == nil {
51-
return nil, fmt.Errorf("Unsupported dialect type: %v", uri.DBType)
55+
return nil, fmt.Errorf("unsupported dialect type: %v", uri.DBType)
5256
}
5357

5458
dialect.Init(uri)

dialects/filter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func convertQuestionMark(sql, prefix string, start int) string {
3838
return buf.String()
3939
}
4040

41+
// Do implements Filter
4142
func (s *SeqFilter) Do(sql string) string {
4243
return convertQuestionMark(sql, s.Prefix, s.Start)
4344
}

dialects/time.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func FormatTime(dialect Dialect, sqlTypeName string, t time.Time) (v interface{}
3838
return
3939
}
4040

41+
// FormatColumnTime format column time
4142
func FormatColumnTime(dialect Dialect, defaultTimeZone *time.Location, col *schemas.Column, t time.Time) (v interface{}) {
4243
if t.IsZero() {
4344
if col.Nullable {

integrations/tests.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ func createEngine(dbType, connStr string) error {
166166
for _, table := range tables {
167167
tableNames = append(tableNames, table.Name)
168168
}
169-
if err = testEngine.DropTables(tableNames...); err != nil {
170-
return err
171-
}
172-
return nil
169+
return testEngine.DropTables(tableNames...)
173170
}
174171

175172
// PrepareEngine prepare tests ORM engine

internal/statements/expr_param.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"xorm.io/xorm/schemas"
1313
)
1414

15+
// ErrUnsupportedExprType represents an error with unsupported express type
1516
type ErrUnsupportedExprType struct {
1617
tp string
1718
}

0 commit comments

Comments
 (0)