repo
stringlengths
6
47
file_url
stringlengths
77
269
file_path
stringlengths
5
186
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-07 08:35:43
2026-01-07 08:55:24
truncated
bool
2 classes
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/where.go
clause/where.go
package clause import ( "strings" ) const ( AndWithSpace = " AND " OrWithSpace = " OR " ) // Where where clause type Where struct { Exprs []Expression } // Name where clause name func (where Where) Name() string { return "WHERE" } // Build build where clause func (where Where) Build(builder Builder) { if le...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/order_by_test.go
clause/order_by_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestOrderBy(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}, clause.OrderBy{ Columns: []clause.OrderByColumn{{Colu...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/group_by.go
clause/group_by.go
package clause // GroupBy group by clause type GroupBy struct { Columns []Column Having []Expression } // Name from clause name func (groupBy GroupBy) Name() string { return "GROUP BY" } // Build build group by clause func (groupBy GroupBy) Build(builder Builder) { for idx, column := range groupBy.Columns { i...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/locking.go
clause/locking.go
package clause const ( LockingStrengthUpdate = "UPDATE" LockingStrengthShare = "SHARE" LockingOptionsSkipLocked = "SKIP LOCKED" LockingOptionsNoWait = "NOWAIT" ) type Locking struct { Strength string Table Table Options string } // Name where clause name func (locking Locking) Name() string { ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/select.go
clause/select.go
package clause // Select select attrs when querying, updating, creating type Select struct { Distinct bool Columns []Column Expression Expression } func (s Select) Name() string { return "SELECT" } func (s Select) Build(builder Builder) { if len(s.Columns) > 0 { if s.Distinct { builder.WriteString("DI...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/delete.go
clause/delete.go
package clause type Delete struct { Modifier string } func (d Delete) Name() string { return "DELETE" } func (d Delete) Build(builder Builder) { builder.WriteString("DELETE") if d.Modifier != "" { builder.WriteByte(' ') builder.WriteString(d.Modifier) } } func (d Delete) MergeClause(clause *Clause) { cla...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/locking_test.go
clause/locking_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestLocking(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}, clause.Locking{Strength: clause.LockingStrengthUpdate}}, ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/delete_test.go
clause/delete_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestDelete(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Delete{}, clause.From{}}, "DELETE FROM `users`", nil, }, { []clause.Inter...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/where_test.go
clause/where_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestWhere(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}, clause.Where{ Exprs: []clause.Expression{clause.Eq{Colu...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/set_test.go
clause/set_test.go
package clause_test import ( "fmt" "sort" "strings" "testing" "gorm.io/gorm/clause" ) // Compile-time assertions that types implement clause.Assigner var ( _ clause.Assigner = clause.Assignment{} _ clause.Assigner = clause.Set{} ) func TestSet(t *testing.T) { results := []struct { Clauses []clause.Interfa...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/on_conflict.go
clause/on_conflict.go
package clause type OnConflict struct { Columns []Column Where Where TargetWhere Where OnConstraint string DoNothing bool DoUpdates Set UpdateAll bool } func (OnConflict) Name() string { return "ON CONFLICT" } // Build build onConflict clause func (onConflict OnConflict) Build(builder B...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/values.go
clause/values.go
package clause type Values struct { Columns []Column Values [][]interface{} } // Name from clause name func (Values) Name() string { return "VALUES" } // Build build from clause func (values Values) Build(builder Builder) { if len(values.Columns) > 0 { builder.WriteByte('(') for idx, column := range values....
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/update_test.go
clause/update_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestUpdate(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Update{}}, "UPDATE `users`", nil, }, { []clause.Interface{clause.Update{M...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/returning.go
clause/returning.go
package clause type Returning struct { Columns []Column } // Name where clause name func (returning Returning) Name() string { return "RETURNING" } // Build build where clause func (returning Returning) Build(builder Builder) { if len(returning.Columns) > 0 { for idx, column := range returning.Columns { if i...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/limit.go
clause/limit.go
package clause // Limit limit clause type Limit struct { Limit *int Offset int } // Name where clause name func (limit Limit) Name() string { return "LIMIT" } // Build build where clause func (limit Limit) Build(builder Builder) { if limit.Limit != nil && *limit.Limit >= 0 { builder.WriteString("LIMIT ") bu...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/select_test.go
clause/select_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestSelect(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}}, "SELECT * FROM `users`", nil, }, { []clause.Int...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/expression.go
clause/expression.go
package clause import ( "database/sql" "database/sql/driver" "go/ast" "reflect" ) // Expression expression interface type Expression interface { Build(builder Builder) } // NegationExpressionBuilder negation expression builder type NegationExpressionBuilder interface { NegationBuild(builder Builder) } // Expr...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/order_by.go
clause/order_by.go
package clause type OrderByColumn struct { Column Column Desc bool Reorder bool } type OrderBy struct { Columns []OrderByColumn Expression Expression } // Name where clause name func (orderBy OrderBy) Name() string { return "ORDER BY" } // Build build where clause func (orderBy OrderBy) Build(builder B...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/values_test.go
clause/values_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestValues(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{ clause.Insert{}, clause.Values{ Columns: []clause.Column{{Name: "name"}, {Na...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/benchmarks_test.go
clause/benchmarks_test.go
package clause_test import ( "sync" "testing" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gorm/utils/tests" ) func BenchmarkSelect(b *testing.B) { user, _ := schema.Parse(&tests.User{}, &sync.Map{}, db.NamingStrategy) for i := 0; i < b.N; i++ { stmt := gorm.Statement{DB: db, Table:...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/set.go
clause/set.go
package clause import "sort" type Set []Assignment type Assignment struct { Column Column Value interface{} } // Assigner assignments provider interface type Assigner interface { Assignments() []Assignment } func (set Set) Name() string { return "SET" } func (set Set) Build(builder Builder) { if len(set) > ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/association.go
clause/association.go
package clause // AssociationOpType represents association operation types type AssociationOpType int const ( OpUnlink AssociationOpType = iota // Unlink association OpDelete // Delete association records OpUpdate // Update association records OpCreate ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/insert_test.go
clause/insert_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestInsert(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Insert{}}, "INSERT INTO `users`", nil, }, { []clause.Interface{clause.Ins...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/clause.go
clause/clause.go
package clause // Interface clause interface type Interface interface { Name() string Build(Builder) MergeClause(*Clause) } // ClauseBuilder clause builder, allows to customize how to build clause type ClauseBuilder func(Clause, Builder) type Writer interface { WriteByte(byte) error WriteString(string) (int, er...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/joins.go
clause/joins.go
package clause import "gorm.io/gorm/utils" type JoinType string const ( CrossJoin JoinType = "CROSS" InnerJoin JoinType = "INNER" LeftJoin JoinType = "LEFT" RightJoin JoinType = "RIGHT" ) type JoinTarget struct { Type JoinType Association string Subquery Expression Table string } func Has(...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/returning_test.go
clause/returning_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestReturning(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}, clause.Returning{ []clause.Column{clause.PrimaryCol...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/insert.go
clause/insert.go
package clause type Insert struct { Table Table Modifier string } // Name insert clause name func (insert Insert) Name() string { return "INSERT" } // Build build insert clause func (insert Insert) Build(builder Builder) { if insert.Modifier != "" { builder.WriteString(insert.Modifier) builder.WriteByte('...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/from_test.go
clause/from_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestFrom(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}}, "SELECT * FROM `users`", nil, }, { []clause.Inter...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/update.go
clause/update.go
package clause type Update struct { Modifier string Table Table } // Name update clause name func (update Update) Name() string { return "UPDATE" } // Build build update clause func (update Update) Build(builder Builder) { if update.Modifier != "" { builder.WriteString(update.Modifier) builder.WriteByte('...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/group_by_test.go
clause/group_by_test.go
package clause_test import ( "fmt" "testing" "gorm.io/gorm/clause" ) func TestGroupBy(t *testing.T) { results := []struct { Clauses []clause.Interface Result string Vars []interface{} }{ { []clause.Interface{clause.Select{}, clause.From{}, clause.GroupBy{ Columns: []clause.Column{{Name: "role...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/clause/joins_test.go
clause/joins_test.go
package clause_test import ( "sync" "testing" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gorm/utils/tests" ) func TestJoin(t *testing.T) { results := []struct { name string join clause.Join sql string }{ { name: "LEFT JOIN", join: clause.Join{ Type: clause.LeftJoi...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/logger/sql.go
logger/sql.go
package logger import ( "database/sql/driver" "fmt" "reflect" "regexp" "strconv" "strings" "time" "unicode" "gorm.io/gorm/utils" ) const ( tmFmtWithMS = "2006-01-02 15:04:05.999" tmFmtZero = "0000-00-00 00:00:00" nullStr = "NULL" ) func isPrintable(s string) bool { for _, r := range s { if !uni...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/logger/sql_test.go
logger/sql_test.go
package logger_test import ( "database/sql/driver" "encoding/json" "fmt" "regexp" "strings" "testing" "github.com/jinzhu/now" "gorm.io/gorm/logger" ) type JSON json.RawMessage func (j JSON) Value() (driver.Value, error) { if len(j) == 0 { return nil, nil } return json.RawMessage(j).MarshalJSON() } typ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/logger/slog_test.go
logger/slog_test.go
//go:build go1.21 package logger import ( "bytes" "context" "log/slog" "strings" "testing" "time" ) func TestSlogLogger(t *testing.T) { buf := &bytes.Buffer{} handler := slog.NewTextHandler(buf, &slog.HandlerOptions{AddSource: true}) logger := NewSlogLogger(slog.New(handler), Config{LogLevel: Info}) logge...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/logger/slog.go
logger/slog.go
//go:build go1.21 package logger import ( "context" "errors" "fmt" "log/slog" "time" "gorm.io/gorm/utils" ) type slogLogger struct { Logger *slog.Logger LogLevel LogLevel SlowThreshold time.Duration Parameterized bool Colorful b...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/logger/logger.go
logger/logger.go
package logger import ( "context" "errors" "fmt" "io" "log" "os" "time" "gorm.io/gorm/utils" ) // ErrRecordNotFound record not found error var ErrRecordNotFound = errors.New("record not found") // Colors const ( Reset = "\033[0m" Red = "\033[31m" Green = "\033[32m" Yellow = "\03...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/scan_test.go
tests/scan_test.go
package tests_test import ( "reflect" "sort" "strings" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) type PersonAddressInfo struct { Person *Person `gorm:"embedded"` Address *Address `gorm:"embedded"` } func TestScan(t *testing.T) { user1 := User{Name: "ScanUser1", Age: 1} user2 := Use...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/preload_suits_test.go
tests/preload_suits_test.go
package tests_test import ( "database/sql" "encoding/json" "reflect" "sort" "sync/atomic" "testing" "gorm.io/gorm" ) func toJSONString(v interface{}) []byte { r, _ := json.Marshal(v) return r } func TestNestedPreload1(t *testing.T) { type ( Level1 struct { ID uint Value string Level2ID...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/update_belongs_to_test.go
tests/update_belongs_to_test.go
package tests_test import ( "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestUpdateBelongsTo(t *testing.T) { user := *GetUser("update-belongs-to", Config{}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } user.Company = Company{Name: "compa...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/associations_test.go
tests/associations_test.go
package tests_test import ( "testing" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" . "gorm.io/gorm/utils/tests" ) func AssertAssociationCount(t *testing.T, data interface{}, name string, result int64, reason string) { if count := DB.Model(data).Association(name).Count(); count != result { t.Fat...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/table_test.go
tests/table_test.go
package tests_test import ( "regexp" "sync" "testing" "gorm.io/driver/gaussdb" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/schema" "gorm.io/gorm/utils/tests" . "gorm.io/gorm/utils/tests" ) type UserWithTable struct { gorm.Model Name string } func (UserWithTable) TableName() string { return "g...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/error_translator_test.go
tests/error_translator_test.go
package tests_test import ( "errors" "testing" "gorm.io/gorm" "gorm.io/gorm/utils/tests" ) func TestDialectorWithErrorTranslatorSupport(t *testing.T) { // it shouldn't translate error when the TranslateError flag is false translatedErr := errors.New("translated error") untranslatedErr := errors.New("some rand...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/non_std_test.go
tests/non_std_test.go
package tests_test import ( "testing" "time" ) type Animal struct { Counter uint64 `gorm:"primary_key:yes"` Name string `gorm:"DEFAULT:'galeone'"` From string // test reserved sql keyword as field name Age *time.Time unexported string // unexported value CreatedAt time.Time UpdatedAt ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/embedded_struct_test.go
tests/embedded_struct_test.go
package tests_test import ( "database/sql/driver" "encoding/json" "errors" "reflect" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestEmbeddedStruct(t *testing.T) { type ReadOnly struct { ReadOnly *bool } type BasePost struct { Id int64 Title string URL string ReadOn...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/named_argument_test.go
tests/named_argument_test.go
package tests_test import ( "database/sql" "errors" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestNamedArg(t *testing.T) { type NamedUser struct { gorm.Model Name1 string Name2 string Name3 string } DB.Migrator().DropTable(&NamedUser{}) DB.AutoMigrate(&NamedUser{}) namedUser :=...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/migrate_test.go
tests/migrate_test.go
package tests_test import ( "context" "database/sql" "fmt" "math/rand" "reflect" "strconv" "strings" "testing" "time" "github.com/stretchr/testify/assert" "gorm.io/driver/gaussdb" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/migrator" "gorm.io/gorm/schema" "gorm.io/go...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
true
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/create_test.go
tests/create_test.go
package tests_test import ( "errors" "fmt" "regexp" "testing" "time" "github.com/jinzhu/now" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestCreate(t *testing.T) { u1 := *GetUser("create", Config{}) if results := DB.Create(&u1); results.Error != nil { t.Fatalf("errors happe...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/helper_test.go
tests/helper_test.go
package tests_test import ( "os" "sort" "strconv" "strings" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) type Config struct { Account bool Pets int Toys int Company bool Manager bool Team int Languages int Friends int NamedPet bool Tools int } func Ge...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/delete_test.go
tests/delete_test.go
package tests_test import ( "errors" "testing" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestDelete(t *testing.T) { users := []User{*GetUser("delete", Config{}), *GetUser("delete", Config{}), *GetUser("delete", Config{})} if err := DB.Create(&users).Error; err != nil { t.Erro...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/customize_field_test.go
tests/customize_field_test.go
package tests_test import ( "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestCustomizeColumn(t *testing.T) { type CustomizeColumn struct { ID int64 `gorm:"column:mapped_id; primary_key:yes"` Name string `gorm:"column:mapped_name"` Date *time.Time `gorm:"column:mapped_time...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/associations_belongs_to_test.go
tests/associations_belongs_to_test.go
package tests_test import ( "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestBelongsToAssociation(t *testing.T) { user := *GetUser("belongs-to", Config{Company: true, Manager: true}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } CheckUser...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/associations_many2many_test.go
tests/associations_many2many_test.go
package tests_test import ( "fmt" "sync" "testing" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestMany2ManyAssociation(t *testing.T) { user := *GetUser("many2many", Config{Languages: 2}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v"...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/soft_delete_test.go
tests/soft_delete_test.go
package tests_test import ( "database/sql" "encoding/json" "errors" "regexp" "testing" "github.com/jinzhu/now" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestSoftDelete(t *testing.T) { user := *GetUser("SoftDelete", Config{}) DB.Save(&user) var count int64 var age uint if DB.Model(&User{}).Whe...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/association_generics_test.go
tests/association_generics_test.go
package tests_test import ( "context" "testing" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) // BelongsToCompany and BelongsToUser models for belongs to tests - using existing User and Company models // Test Set + Create with Association OpCreate operation using real database func TestCl...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
true
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/query_test.go
tests/query_test.go
package tests_test import ( "database/sql" "database/sql/driver" "fmt" "reflect" "regexp" "sort" "strconv" "strings" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestFind(t *testing.T) { users := []User{ *GetUser("find", Config{}), *GetUser("find", Confi...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
true
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/count_test.go
tests/count_test.go
package tests_test import ( "regexp" "sort" "strings" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestCountWithGroup(t *testing.T) { DB.Create([]Company{ {Name: "company_count_group_a"}, {Name: "company_count_group_a"}, {Name: "company_count_group_a"}, {Name: "company_count_group_b"},...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/prepared_stmt_test.go
tests/prepared_stmt_test.go
package tests_test import ( "context" "errors" "sync" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestPreparedStmt(t *testing.T) { tx := DB.Session(&gorm.Session{PrepareStmt: true}) if _, ok := tx.ConnPool.(*gorm.PreparedStmtDB); !ok { t.Fatalf("should assign PreparedStatement Man...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/update_test.go
tests/update_test.go
package tests_test import ( "errors" "regexp" "sort" "strings" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/utils" . "gorm.io/gorm/utils/tests" ) func TestUpdate(t *testing.T) { var ( users = []*User{ GetUser("update-1", Config{}), GetUser("update-2", Config{}), GetUser("...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/main_test.go
tests/main_test.go
package tests_test import ( "testing" . "gorm.io/gorm/utils/tests" ) func TestExceptionsWithInvalidSql(t *testing.T) { if name := DB.Dialector.Name(); name == "sqlserver" { t.Skip("skip sqlserver due to it will raise data race for invalid sql") } var columns []string if DB.Where("sdsd.zaaa = ?", "sd;;;aa")....
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/distinct_test.go
tests/distinct_test.go
package tests_test import ( "regexp" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestDistinct(t *testing.T) { users := []User{ *GetUser("distinct", Config{}), *GetUser("distinct", Config{}), *GetUser("distinct", Config{}), *GetUser("distinct-2", Config{}), *GetUser("distinct-3", Confi...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/connection_test.go
tests/connection_test.go
package tests_test import ( "testing" "gorm.io/driver/mysql" "gorm.io/gorm" ) func TestWithSingleConnection(t *testing.T) { expectedName := "test" var actualName string setSQL, getSQL := getSetSQL(DB.Dialector.Name()) if len(setSQL) == 0 || len(getSQL) == 0 { return } err := DB.Connection(func(tx *gorm....
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/upsert_test.go
tests/upsert_test.go
package tests_test import ( "regexp" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestUpsert(t *testing.T) { lang := Language{Code: "upsert", Name: "Upsert"} if err := DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&lang).Error; err != nil { t.Fatalf("fai...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/connpool_test.go
tests/connpool_test.go
package tests_test import ( "context" "database/sql" "os" "reflect" "testing" "gorm.io/driver/mysql" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) type wrapperTx struct { *sql.Tx conn *wrapperConnPool } func (c *wrapperTx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) { c.conn.got ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/preload_test.go
tests/preload_test.go
package tests_test import ( "context" "encoding/json" "regexp" "sort" "strconv" "sync" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestPreloadWithAssociations(t *testing.T) { user := *GetUser("preload_with_associations", Config{ Account: true, Pets: ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/lru_test.go
tests/lru_test.go
package tests_test import ( "crypto/rand" "fmt" "math" "math/big" "reflect" "sync" "testing" "time" "gorm.io/gorm/internal/lru" ) func TestLRU_Add_ExistingKey_UpdatesValueAndExpiresAt(t *testing.T) { lru := lru.NewLRU[string, int](10, nil, time.Hour) lru.Add("key1", 1) lru.Add("key1", 2) if value, ok :...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/update_many2many_test.go
tests/update_many2many_test.go
package tests_test import ( "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestUpdateMany2ManyAssociations(t *testing.T) { user := *GetUser("update-many2many", Config{}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } user.Languages = []Langu...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/scanner_valuer_test.go
tests/scanner_valuer_test.go
package tests_test import ( "context" "database/sql" "database/sql/driver" "encoding/json" "errors" "fmt" "reflect" "regexp" "strconv" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestScannerValuer(t *testing.T) { DB.Migrator().DropTable(&ScannerValuerStruc...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/tests_test.go
tests/tests_test.go
//go:debug x509negativeserial=1 package tests_test import ( "log" "math/rand" "os" "path/filepath" "time" "gorm.io/driver/gaussdb" "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/driver/sqlite" "gorm.io/driver/sqlserver" "gorm.io/gorm" "gorm.io/gorm/logger" . "gorm.io/gorm/utils/tests" ) var D...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/gorm_test.go
tests/gorm_test.go
package tests_test import ( "testing" "gorm.io/driver/mysql" "gorm.io/gorm" ) func TestOpen(t *testing.T) { dsn := "gorm:gorm@tcp(localhost:9910)/gorm?loc=Asia%2FHongKong" // invalid loc _, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err == nil { t.Fatalf("should returns error but got nil") } } f...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/default_value_test.go
tests/default_value_test.go
package tests_test import ( "testing" "time" "gorm.io/gorm" ) func TestDefaultValue(t *testing.T) { type Harumph struct { gorm.Model Email string `gorm:"not null;index:,unique"` Name string `gorm:"notNull;default:foo"` Name2 string `gorm:"size:233;not null;default:'foo'"` Name3 string...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/scopes_test.go
tests/scopes_test.go
package tests_test import ( "context" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func NameIn1And2(d *gorm.DB) *gorm.DB { return d.Where("name in (?)", []string{"ScopeUser1", "ScopeUser2"}) } func NameIn2And3(d *gorm.DB) *gorm.DB { return d.Where("name in (?)", []string{"ScopeUser2", "ScopeUser3"}...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/hooks_test.go
tests/hooks_test.go
package tests_test import ( "errors" "log" "os" "reflect" "strings" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) type Product struct { gorm.Model Name string Code string Price float64 AfterFindCallTimes int64 BeforeCreateCallTimes int64 A...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/associations_has_one_test.go
tests/associations_has_one_test.go
package tests_test import ( "testing" . "gorm.io/gorm/utils/tests" ) func TestHasOneAssociation(t *testing.T) { user := *GetUser("hasone", Config{Account: true}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } CheckUser(t, user, user) // Find var user2 U...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/associations_has_many_test.go
tests/associations_has_many_test.go
package tests_test import ( "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestHasManyAssociation(t *testing.T) { user := *GetUser("hasmany", Config{Pets: 2}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } CheckUser(t, user, user) // Find ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/benchmark_test.go
tests/benchmark_test.go
package tests_test import ( "fmt" "testing" . "gorm.io/gorm/utils/tests" ) func BenchmarkCreate(b *testing.B) { user := *GetUser("bench", Config{}) for x := 0; x < b.N; x++ { user.ID = 0 DB.Create(&user) } } func BenchmarkFind(b *testing.B) { user := *GetUser("find", Config{}) DB.Create(&user) for x ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/multi_primary_keys_test.go
tests/multi_primary_keys_test.go
package tests_test import ( "reflect" "sort" "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) type Blog struct { ID uint `gorm:"primary_key"` Locale string `gorm:"primary_key"` Subject string Body string Tags []Tag `gorm:"many2many:blog_tags;"` SharedTags []Tag `gorm:"m...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/callbacks_test.go
tests/callbacks_test.go
package tests_test import ( "fmt" "reflect" "runtime" "strings" "testing" "gorm.io/gorm" ) func assertCallbacks(v interface{}, fnames []string) (result bool, msg string) { var ( got []string funcs = reflect.ValueOf(v).Elem().FieldByName("fns") ) for i := 0; i < funcs.Len(); i++ { got = append(got, ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/gaussdb_test.go
tests/gaussdb_test.go
package tests_test import ( "testing" "time" "github.com/google/uuid" "github.com/lib/pq" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestGaussDBReturningIDWhichHasStringType(t *testing.T) { t.Skipf("This test case skipped, because of gaussdb not support pgcrypto extension and ge...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/sql_builder_test.go
tests/sql_builder_test.go
package tests_test import ( "regexp" "strings" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestRow(t *testing.T) { user1 := User{Name: "RowUser1", Age: 1} user2 := User{Name: "RowUser2", Age: 10} user3 := User{Name: "RowUser3", Age: 20} DB.Save(&user1).Save(&u...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/tracer_test.go
tests/tracer_test.go
package tests_test import ( "context" "time" "gorm.io/gorm/logger" ) type Tracer struct { Logger logger.Interface Test func(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) } func (S Tracer) LogMode(level logger.LogLevel) logger.Interface { return S.Logger.LogMode...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/postgres_test.go
tests/postgres_test.go
package tests_test import ( "testing" "time" "github.com/google/uuid" "github.com/lib/pq" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestPostgresReturningIDWhichHasStringType(t *testing.T) { if DB.Dialector.Name() != "postgres" { t.Skip() } type Yasuo struct { ID s...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/generics_test.go
tests/generics_test.go
package tests_test import ( "context" "errors" "fmt" "reflect" "regexp" "sort" "strconv" "strings" "sync" "testing" "github.com/google/uuid" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/clause" . "gorm.io/gorm/utils/tests" ) func TestGenericsCreate(t *testing.T) { ctx := context.Background() ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
true
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/update_has_one_test.go
tests/update_has_one_test.go
package tests_test import ( "database/sql" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestUpdateHasOne(t *testing.T) { user := *GetUser("update-has-one", Config{}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } user.Account = Ac...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/update_has_many_test.go
tests/update_has_many_test.go
package tests_test import ( "testing" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestUpdateHasManyAssociations(t *testing.T) { user := *GetUser("update-has-many", Config{}) if err := DB.Create(&user).Error; err != nil { t.Fatalf("errors happened when create: %v", err) } user.Pets = []*Pet{{Name: "...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/joins_table_test.go
tests/joins_table_test.go
package tests_test import ( "testing" "time" "gorm.io/gorm" "gorm.io/gorm/clause" ) type Person struct { ID int Name string Addresses []Address `gorm:"many2many:person_addresses;"` DeletedAt gorm.DeletedAt } type Address struct { ID uint Name string } type PersonAddress struct { PersonID ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/named_polymorphic_test.go
tests/named_polymorphic_test.go
package tests_test import ( "testing" . "gorm.io/gorm/utils/tests" ) type Hamster struct { Id int Name string PreferredToy Toy `gorm:"polymorphic:Owner;polymorphicValue:hamster_preferred"` OtherToy Toy `gorm:"polymorphic:Owner;polymorphicValue:hamster_other"` } func TestNamedPolymorphic(...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/transaction_test.go
tests/transaction_test.go
package tests_test import ( "context" "errors" "testing" "time" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestTransaction(t *testing.T) { tx := DB.Begin() user := *GetUser("transaction", Config{}) if err := tx.Save(&user).Error; err != nil { t.Fatalf("No error should raise, but got %v", err) } ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/serializer_test.go
tests/serializer_test.go
package tests_test import ( "bytes" "context" "fmt" "reflect" "strings" "testing" "time" "gorm.io/gorm" "gorm.io/gorm/schema" . "gorm.io/gorm/utils/tests" ) type SerializerStruct struct { gorm.Model Name []byte `gorm:"json"` Roles Roles ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/group_by_test.go
tests/group_by_test.go
package tests_test import ( "testing" . "gorm.io/gorm/utils/tests" ) func TestGroupBy(t *testing.T) { users := []User{{ Name: "groupby", Age: 10, Birthday: Now(), Active: true, }, { Name: "groupby", Age: 20, Birthday: Now(), }, { Name: "groupby", Age: 30, Birthda...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/joins_test.go
tests/joins_test.go
package tests_test import ( "fmt" "regexp" "sort" "testing" "github.com/stretchr/testify/assert" "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) func TestJoins(t *testing.T) { user := *GetUser("joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false}) DB.Create(&user) var user2 User ...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/tests/submodel_test.go
tests/submodel_test.go
package tests_test import ( "testing" "gorm.io/gorm" ) type Man struct { ID int Age int Name string Detail string } // Panic-safe BeforeUpdate hook that checks for Changed("age") func (m *Man) BeforeUpdate(tx *gorm.DB) (err error) { if !tx.Statement.Changed("age") { return nil } return nil } fu...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/utils_unix_test.go
utils/utils_unix_test.go
//go:build unix // +build unix package utils import ( "testing" ) func TestSourceDir(t *testing.T) { cases := []struct { file string want string }{ { file: "/Users/name/go/pkg/mod/gorm.io/gorm@v1.2.3/utils/utils.go", want: "/Users/name/go/pkg/mod/gorm.io/", }, { file: "/go/work/proj/gorm/utils/...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/utils.go
utils/utils.go
package utils import ( "database/sql/driver" "fmt" "path/filepath" "reflect" "runtime" "strconv" "strings" "unicode" ) var gormSourceDir string func init() { _, file, _, _ := runtime.Caller(0) // compatible solution to get gorm source directory with various operating systems gormSourceDir = sourceDir(file...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/utils_test.go
utils/utils_test.go
package utils import ( "database/sql" "database/sql/driver" "errors" "math" "strings" "testing" "time" ) func TestIsInvalidDBNameChar(t *testing.T) { for _, db := range []string{"db", "dbName", "db_name", "db1", "1dbname", "db$name"} { if fields := strings.FieldsFunc(db, IsInvalidDBNameChar); len(fields) !=...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/utils_windows_test.go
utils/utils_windows_test.go
package utils import ( "testing" ) func TestSourceDir(t *testing.T) { cases := []struct { file string want string }{ { file: `C:/Users/name/go/pkg/mod/gorm.io/gorm@v1.2.3/utils/utils.go`, want: `C:/Users/name/go/pkg/mod/gorm.io/`, }, { file: `C:/go/work/proj/gorm/utils/utils.go`, want: `C:/go...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/tests/models.go
utils/tests/models.go
package tests import ( "database/sql" "time" "gorm.io/gorm" ) // User has one `Account` (has one), many `Pets` (has many) and `Toys` (has many - polymorphic) // He works in a Company (belongs to), he has a Manager (belongs to - single-table), and also managed a Team (has many - single-table) // He speaks many lan...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/tests/utils.go
utils/tests/utils.go
package tests import ( "database/sql/driver" "fmt" "go/ast" "reflect" "testing" "time" "gorm.io/gorm/utils" ) func AssertObjEqual(t *testing.T, r, e interface{}, names ...string) { for _, name := range names { rv := reflect.Indirect(reflect.ValueOf(r)) ev := reflect.Indirect(reflect.ValueOf(e)) if rv.I...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/utils/tests/dummy_dialecter.go
utils/tests/dummy_dialecter.go
package tests import ( "gorm.io/gorm" "gorm.io/gorm/callbacks" "gorm.io/gorm/clause" "gorm.io/gorm/logger" "gorm.io/gorm/schema" ) type DummyDialector struct { TranslatedErr error } func (DummyDialector) Name() string { return "dummy" } func (DummyDialector) Initialize(db *gorm.DB) error { callbacks.Registe...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/callbacks/create.go
callbacks/create.go
package callbacks import ( "fmt" "reflect" "strings" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gorm/utils" ) // BeforeCreate before create hooks func BeforeCreate(db *gorm.DB) { if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.Befor...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false
go-gorm/gorm
https://github.com/go-gorm/gorm/blob/0d9141bad9772c6047ecfdb2819d8a52d27ceb65/callbacks/helper.go
callbacks/helper.go
package callbacks import ( "reflect" "sort" "gorm.io/gorm" "gorm.io/gorm/clause" ) // ConvertMapToValuesForCreate convert map to values func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]interface{}) (values clause.Values) { values.Columns = make([]clause.Column, 0, len(mapValue)) selec...
go
MIT
0d9141bad9772c6047ecfdb2819d8a52d27ceb65
2026-01-07T08:35:52.485253Z
false