Comments (6)
You'll need to implement Scan and Value on your JSON
type to provide to and from transformers.
from dat.
If you can adapt to using []byte
instead, this implementation by @ansel1 is handy: https://github.com/jinzhu/gorm/issues/516#issuecomment-109055198
from dat.
@Gurpartap Thanks. @atrniv solved this problem for me the same way. I forgot this issue since we moved away from dat.
type JSONO map[string]interface{}
type JSONA []interface{}
func (jo JSONO) String() string {
data, err := json.Marshal(jo)
if err != nil {
panic(err.Error())
}
return string(data)
}
func (jo JSONO) Value() (driver.Value, error) {
return json.Marshal(jo)
}
func (jo JSONO) Scan(data []byte) error {
return json.Unmarshal(data, jo)
}
from dat.
Using this approach I'm getting (JSONMap is same as JSONO):
<*errors.errorString | 0xc420165810>: {
s: "sql: converting Exec argument #2's type: unsupported type map[interface {}]interface {}, a map",
}
My model is:
type Game struct {
ID string `db:"id"`
Name string `db:"name"`
Metadata JSONMap `db:"metadata"`
CreatedAt dat.NullTime `db:"created_at"`
UpdatedAt dat.NullTime `db:"updated_at"`
}
The dat code is:
//Metadata defaults to {}
game := models.Game{
Name: uuid.NewV4().String(),
}
err := db.
InsertInto("games").
Record(&game).
Returning("id", "created_at", "updated_at").
QueryStruct(&game)
Any ideas?
from dat.
What is metadata
postgres type, jsonb
? I would recommend dat.JSON
for jsonb
.
I'm not familiar with JSONO
type? Please provide gist of DDL for game and type definition of JSONMap.
from dat.
Sorry man. Was actually a problem with fixtures. I just found out, like a minute ago, lol. Thanks for the fast response. Awesome lib.
from dat.
Related Issues (20)
- IN queries and MustInterpolate HOT 4
- New v1 tag HOT 1
- Something change recently with dat.v1? HOT 2
- maxLookup index out of range on update HOT 3
- Disabling logger makes errors become nil, and generates nil pointer dereferences HOT 3
- unsupported type []interface {}, a slice HOT 1
- MustPing with timeout HOT 3
- Referential Integrity errors log goroutines dying HOT 4
- What's the state of v2? HOT 5
- Can dat work with mysql? HOT 1
- logxi HOT 3
- No buildable Go source files HOT 2
- no buildable Go source files (logxi) HOT 6
- Glide requirement causing major issues HOT 5
- Panic in Exec() method
- Current status of dat project HOT 12
- hod
- `LIKE` operator in queries HOT 1
- sqlx-runner exec error HOT 1
- Dependency issue with mgutz logxi
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dat.