profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/lichunqiang/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
__FresHmaN lichunqiang China Beijing Contributor of @vuxjs and @fecshop , soft engineer at the earth, love to the open source.

airyland/vux 17531

Mobile UI Components based on Vue & WeUI

lichunqiang/awesome-stars 67

:book: My own stars :star:

lichunqiang/composer-ignore-plugin 20

The composer plugin to remove useless files by yourself

lichunqiang/apistore 9

PHPSDK for Baidu APIStore

lichunqiang/coding-notifier-chrome 2

Chrome extension of Coding.net notification

0x2766/yiihub 1

yunjianyi.com is A high performance open-source forum software written in Yii2.

lichunqiang/awesome-yii2 1

Yii2 干货集

lichunqiang/b 1

blog backups

lichunqiang/black-ip-list 1

collection of bad man ip list

lichunqiang/csphere-training 1

csphere docker training notes

startedgorilla/csrf

started time in 4 hours

startedfanux/sealos

started time in 9 days

startedbigskysoftware/htmx

started time in 11 days

startedxeipuuv/gojsonschema

started time in 12 days

startedcloudwego/netpoll

started time in 13 days

startedalibaba/canal

started time in 15 days

startedpingcap/dumpling

started time in 15 days

startedbytedance/sonic

started time in 19 days

startedneilotoole/errgroup

started time in 20 days

startedgolang-design/lockfree

started time in 20 days

startedsmallnest/rpcx

started time in 20 days

startedrcrowley/go-metrics

started time in 20 days

startedmarusama/cyclicbarrier

started time in 20 days

startedtidwall/gjson

started time in 20 days

startedtal-tech/cds

started time in 21 days

startedgolang/sync

started time in 21 days

fork lichunqiang/precommit-vet-lint

A precommit hook that runs Golint and Vet on your staged go files.

fork in a month

startedrakyll/statik

started time in a month

startedgolang101/golang101

started time in a month

startedouqiang/gocron

started time in a month

startedgo-admin-team/go-admin

started time in a month

startedsecurego/gosec

started time in a month

startedtidwall/btree

started time in 2 months

startedgolang-design/Go-Questions

started time in 2 months

issue closedgo-gorm/gorm

custom data type field's value is always string in where clauses

<!-- DON'T CHANGE THE TEMPLATE -->

Your Question

type ID uint64

func (i ID) GormDataType() string {
	return "uint"
}

type Model struct {
	ID ID `gorm:"primaryKey"`
}

type mockModel struct {
	//Model
	ID   ID
	Name string
}

func main() {
	db := gorm.New()
	ctx := context.Background()

	var id ID = 1111
	var m = mockModel{}
	m.ID = id

	tx := orm.WithContext(ctx).Debug().Model(&m)
	err = tx.Take(&m).Error
	if err != nil {
		panic(err)
	}
	fmt.Println(m)
	fmt.Println(tx.Explain("id = ?", id))
}

output:

[0.350ms] [rows:1] SELECT * FROM `mock_models` WHERE `mock_models`.`id` = '1111' LIMIT 1
{1111 limu}
id = '1111'

<!-- Most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io, ✨ Search Before Asking ✨ -->

<!-- Ask your question in English, minimalist example is highly recommended, please Report a bug for bugs -->

The document you expected this should be explained

after searched the documents, https://gorm.io/docs/data_types.html . Implements the GormDataTypeInterface

<!-- The document link you expected this question should be explained in our official documents site -->

Expected answer

<!-- What you want -->

Expected:

SELECT * FROM `mock_models` WHERE `mock_models`.`id` = 1111 LIMIT 1

closed time in 2 months

lichunqiang

issue commentgo-gorm/gorm

custom data type field's value is always string in where clauses

resolved.

implements the Valuer interface

lichunqiang

comment created time in 2 months

issue commentgo-gorm/gorm

custom data type field's value is always string in where clauses

version: gorm.io/gorm v1.21.12

lichunqiang

comment created time in 2 months

issue openedgo-gorm/gorm

custom data type field's value is always string in where clauses

<!-- DON'T CHANGE THE TEMPLATE -->

Your Question

type ID uint64

func (i ID) GormDataType() string {
	return "uint"
}

type Model struct {
	ID ID `gorm:"primaryKey"`
}

type mockModel struct {
	//Model
	ID   ID
	Name string
}

func main() {
	db := gorm.New()
	ctx := context.Background()

	var id ID = 1111
	var m = mockModel{}
	m.ID = id

	tx := orm.WithContext(ctx).Debug().Model(&m)
	err = tx.Take(&m).Error
	if err != nil {
		panic(err)
	}
	fmt.Println(m)
	fmt.Println(tx.Explain("id = ?", id))
}

output:

[0.350ms] [rows:1] SELECT * FROM `mock_models` WHERE `mock_models`.`id` = '1111' LIMIT 1
{1111 limu}
id = '1111'

<!-- Most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io, ✨ Search Before Asking ✨ -->

<!-- Ask your question in English, minimalist example is highly recommended, please Report a bug for bugs -->

The document you expected this should be explained

after searched the documents, https://gorm.io/docs/data_types.html . Implements the GormDataTypeInterface

<!-- The document link you expected this question should be explained in our official documents site -->

Expected answer

<!-- What you want -->

Expected:

SELECT * FROM `mock_models` WHERE `mock_models`.`id` = 1111 LIMIT 1

created time in 2 months

startedgabriel-vasile/mimetype

started time in 2 months

startedgo-mysql-org/go-mysql

started time in 2 months