jackskj / carta Goto Github PK
View Code? Open in Web Editor NEWSQL data mapper for Go
Home Page: https://jackskj.github.io/carta/
License: Apache License 2.0
SQL data mapper for Go
Home Page: https://jackskj.github.io/carta/
License: Apache License 2.0
I have a use case where a user can have multiple posts. When I use carts.Map I get:
{
user_id: 1
posts: [
{
post_id: null
content: null
}
]
}
But what I want is:
{
user_id: 1
posts: []
}
as title
It shows timestamp always as "createTimestamp": "0001-01-01T00:00:00Z" "updateTimestamp": "0001-01-01T00:00:00Z" when mapping a sql timestamp into a time.Time variable .
How to mapping sqlx with carta?
I have a geometry column in one of my tables and for that I have defined a custom data type with Scan and Value methods like this:
type Point struct {
X float64
Y float64
Z float64
}
type Coordinate Point
// Scan scan value into geom.Point, implements sql.Scanner interface
func (c *Coordinate) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("not a byte" array)
}
dst := make([]byte, len(b))
_, err := hex.Decode(dst, b)
if err != nil {
return err
}
gt, err := ewkb.Unmarshal(dst)
if err != nil {
return err
}
c.X = gt.FlatCoords()[0]
c.Y = gt.FlatCoords()[1]
return nil
}
// Converting cordinate to geom.point
func (c Coordinate) Value() (driver.Value, error) {
b := geom.NewPoint(geom.XY)
b.SetCoords(geom.Coord{c.X, c.Y})
a, err := wkt.Marshal(b)
s := fmt.Sprintf("SRID=%d;%s", 4326, a)
return s, err
}
And this Coordinate type is used in the DB struct like show below:
type Survey struct {
SurveyID string `db:"survey_id"`
CompanyName string `db:"company_name"`
Gcps []Gcp
}
type Gcp struct {
GcpID int64 `db:"gcp_id"`
PointID string `db:"point_id"`
Coordinate *Coordinate `db:"coordinate"`
}
When I try to map the DB rows to the Survey model, all the fields are mapped but the coordinate is left out and its Scan method is never called.
Following is the code snippet:
rows, err := i.db.Query(query)
if err != nil {
log.Error(err)
return nil, err
}
fs := []model.Survey{}
err = carta.Map(rows, &fs)
if err != nil {
log.Error(err)
return nil, err
}
Carta looks great so far. :-)
But there seems to be a conflict with null.v4.
Relevant code:
import (
"gopkg.in/guregu/null.v4"
"github.com/jackskj/carta"
)
type User struct {
ID int `json:"-"`
FirstName null.String `json:"first_name"`
LastName null.String `json:"last_name"`
Email string `json:"email"`
}
What happens:
Expected result:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.