Code Monkey home page Code Monkey logo

carta's People

Contributors

jackskj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

carta's Issues

Does not work for custom data type

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 appears to conflict with gopkg.in/guregu/null.v4

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:

  • Non-null first and last names are returned as null.

Expected result:

  • Non-null values should work as expected while using null.v4 and carta packages in the same app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.