8000 conflicted where case · Issue #7356 · go-gorm/gorm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
conflicted where case #7356
Closed as not planned
Closed as not planned
@lysShub

Description

@lysShub

GORM Playground Link

go-gorm/playground#1

Description

package main

import (
	"context"
	"database/sql"
	"fmt"
	"time"

	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func main() {

	db := newdb()

	rec := &User{}
	res := db.First(rec, User{UserID: 123, DeletedAt: gorm.DeletedAt{Valid: true}})
	if err := res.Error; err != nil {
		panic(err)
	}
	q := res.Statement.SQL.String()

	fmt.Println(q)
	// SELECT * FROM "users" WHERE ("users"."user_id" = $1 AND "users"."deleted_at" = $2) AND "users"."deleted_at" IS NULL ORDER BY "users"."user_id" LIMIT $3
}

type User struct {
	UserID  uint32 `gorm:"primaryKey;autoIncrement"` //
	Session uint32

	CreatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

func newdb() *gorm.DB {
	dialer := postgres.Dialector{Config: &postgres.Config{
		Conn: &mockConnPool{},
	}}
	db, err := gorm.Open(dialer, &gorm.Config{DryRun: true})
	if err != nil {
		panic(err)
	}
	return db
}

type mockConnPool struct{}

func (mockConnPool) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
	return nil, nil
}
func (mockConnPool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
	return nil, nil
}
func (mockConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
	return nil, nil
}
func (mockConnPool) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
	return nil
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0