Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion migrate/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func NewAutoMigrator(db *bun.DB, opts ...AutoMigratorOption) (*AutoMigrator, err
return nil, err
}
am.dbInspector = dbInspector
am.diffOpts = append(am.diffOpts, withCompareTypeFunc(db.Dialect().(sqlschema.InspectorDialect).CompareType))
modelInspector := db.Dialect().(sqlschema.InspectorDialect)
am.diffOpts = append(am.diffOpts, withCompareTypeFunc(modelInspector.CompareType))

dbMigrator, err := sqlschema.NewMigrator(db, am.schemaName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_column_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (q *AddColumnQuery) Exec(ctx context.Context, dest ...any) (sql.Result, err
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*AddColumnQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_column_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (q *DropColumnQuery) AppendQuery(gen schema.QueryGen, b []byte) (_ []byte,

func (q *DropColumnQuery) Exec(ctx context.Context, dest ...any) (sql.Result, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*DropColumnQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (q *DeleteQuery) scanOrExec(
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*DeleteQuery](ctx, q)

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
Expand Down
2 changes: 1 addition & 1 deletion query_index_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (q *CreateIndexQuery) AppendQuery(gen schema.QueryGen, b []byte) (_ []byte,

func (q *CreateIndexQuery) Exec(ctx context.Context, dest ...any) (sql.Result, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*CreateIndexQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_index_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (q *DropIndexQuery) AppendQuery(gen schema.QueryGen, b []byte) (_ []byte, e

func (q *DropIndexQuery) Exec(ctx context.Context, dest ...any) (sql.Result, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*DropIndexQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions query_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (q *InsertQuery) WithQuery(query *WithQuery) *InsertQuery {
return q
}


//------------------------------------------------------------------------------

func (q *InsertQuery) Table(tables ...string) *InsertQuery {
Expand Down Expand Up @@ -590,7 +589,7 @@ func (q *InsertQuery) scanOrExec(
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*InsertQuery](ctx, q)

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
Expand Down
2 changes: 1 addition & 1 deletion query_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (q *MergeQuery) scanOrExec(
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*MergeQuery](ctx, q)

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
Expand Down
2 changes: 1 addition & 1 deletion query_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (q *RawQuery) scanOrExec(
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*RawQuery](ctx, q)

query := q.db.format(q.query, q.args)
var res sql.Result
Expand Down
12 changes: 6 additions & 6 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func (q *SelectQuery) Rows(ctx context.Context) (*sql.Rows, error) {
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand All @@ -882,7 +882,7 @@ func (q *SelectQuery) Exec(ctx context.Context, dest ...any) (res sql.Result, er
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down Expand Up @@ -946,7 +946,7 @@ func (q *SelectQuery) scanResult(ctx context.Context, dest ...any) (sql.Result,
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func (q *SelectQuery) Count(ctx context.Context) (int, error) {
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

qq := countQuery{q}

Expand Down Expand Up @@ -1117,7 +1117,7 @@ func (q *SelectQuery) Exists(ctx context.Context) (bool, error) {

func (q *SelectQuery) selectExists(ctx context.Context) (bool, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

qq := selectExistsQuery{q}

Expand All @@ -1139,7 +1139,7 @@ func (q *SelectQuery) selectExists(ctx context.Context) (bool, error) {

func (q *SelectQuery) whereExists(ctx context.Context) (bool, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*SelectQuery](ctx, q)

qq := whereExistsQuery{q}

Expand Down
2 changes: 1 addition & 1 deletion query_table_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (q *CreateTableQuery) Exec(ctx context.Context, dest ...any) (sql.Result, e
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*CreateTableQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_table_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (q *DropTableQuery) Exec(ctx context.Context, dest ...any) (sql.Result, err
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*DropTableQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_table_truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (q *TruncateTableQuery) AppendQuery(

func (q *TruncateTableQuery) Exec(ctx context.Context, dest ...any) (sql.Result, error) {
// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*TruncateTableQuery](ctx, q)

queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func (q *UpdateQuery) scanOrExec(
}

// if a comment is propagated via the context, use it
setCommentFromContext(ctx, q)
setCommentFromContext[*UpdateQuery](ctx, q)

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.gen, q.db.makeQueryBytes())
Expand Down
10 changes: 5 additions & 5 deletions schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func (t *Table) processFields(typ reflect.Type) {
sf := typ.Field(i)
unexported := sf.PkgPath != ""

tagstr := sf.Tag.Get("bun")
if tagstr == "-" {
tagStr := sf.Tag.Get("bun")
if tagStr == "-" {
names[sf.Name] = struct{}{}
continue
}
tag := tagparser.Parse(tagstr)
tag := tagparser.Parse(tagStr)

if unexported && !sf.Anonymous { // unexported
continue
Expand Down Expand Up @@ -177,8 +177,8 @@ func (t *Table) processFields(typ reflect.Type) {
}
}

if tagstr != "" {
tag := tagparser.Parse(tagstr)
if tagStr != "" {
tag := tagparser.Parse(tagStr)
if tag.HasOption("inherit") || tag.HasOption("extend") {
t.Name = subtable.Name
t.TypeName = subtable.TypeName
Expand Down
Loading