go-gorm

Using a subquery in 'FROM' in gorm

倾然丶 夕夏残阳落幕 提交于 2020-07-17 08:43:25
问题 I would like to know how I can use a subquery in FROM clause using gorm. It would look like the following: SELECT * FROM ( SELECT foo.* FROM foo WHERE bar = "baz" ) AS t1 WHERE t1.id = 1; I have built the subquery using golang: db.Model(Foo{}).Where("bar = ?", "baz") But how can I use this as a subquery in FROM ? If there is a method that turns a gorm query into a SQL string, then I can simply plug that string into a raw SQL. But there does not seem to be such method. Any suggestions? 回答1:

Using a subquery in 'FROM' in gorm

a 夏天 提交于 2020-07-17 08:42:59
问题 I would like to know how I can use a subquery in FROM clause using gorm. It would look like the following: SELECT * FROM ( SELECT foo.* FROM foo WHERE bar = "baz" ) AS t1 WHERE t1.id = 1; I have built the subquery using golang: db.Model(Foo{}).Where("bar = ?", "baz") But how can I use this as a subquery in FROM ? If there is a method that turns a gorm query into a SQL string, then I can simply plug that string into a raw SQL. But there does not seem to be such method. Any suggestions? 回答1:

Using a subquery in 'FROM' in gorm

喜欢而已 提交于 2020-07-17 08:42:21
问题 I would like to know how I can use a subquery in FROM clause using gorm. It would look like the following: SELECT * FROM ( SELECT foo.* FROM foo WHERE bar = "baz" ) AS t1 WHERE t1.id = 1; I have built the subquery using golang: db.Model(Foo{}).Where("bar = ?", "baz") But how can I use this as a subquery in FROM ? If there is a method that turns a gorm query into a SQL string, then I can simply plug that string into a raw SQL. But there does not seem to be such method. Any suggestions? 回答1:

golang - mysql driver - database functions

£可爱£侵袭症+ 提交于 2020-06-26 07:28:40
问题 I have created a struct to store spatial types and I have created a scan function to help query rows in my database. I am having issues inserting this type. I can insert data using the following sql; INSERT INTO 'table' ('spot') VALUES (GeomFromText('POINT(10 10)')); If I use Value interface in database/sql/driver ; type Value interface{} Value is a value that drivers must be able to handle. It is either nil or an instance of one of these types: int64 float64 bool []byte string [*] everywhere

golang - mysql driver - database functions

和自甴很熟 提交于 2020-06-26 07:28:29
问题 I have created a struct to store spatial types and I have created a scan function to help query rows in my database. I am having issues inserting this type. I can insert data using the following sql; INSERT INTO 'table' ('spot') VALUES (GeomFromText('POINT(10 10)')); If I use Value interface in database/sql/driver ; type Value interface{} Value is a value that drivers must be able to handle. It is either nil or an instance of one of these types: int64 float64 bool []byte string [*] everywhere