Giter Site home page Giter Site logo

question: how exec join query about godb HOT 2 CLOSED

samonzeweb avatar samonzeweb commented on September 23, 2024
question: how exec join query

from godb.

Comments (2)

derkan avatar derkan commented on September 23, 2024

Example:

type Author struct {
	ID        int    `db:"id" json:"id"`
	Firstname string `db:"firstname" json:"firstname"`
	Lastname  string `db:"lastname" json:"lastname"`
}

type Book struct {
	ID       int           `db:"id" json:"id"`
	AuthorID sql.NullInt64 `db:"author_id" json:"author_id"`
	Title    string        `db:"title" json:"title"`
}

type BookInfo struct {
	Book   `db:",rel=b" json:"book"`
	Author `db:",rel=a" json:"author"`
}
 // ....
var books []BookInfo
	err = db.SelectFrom("books as b").
		LeftJoin("authors", "a", godb.Q("b.author_id = a.id")).Do(&books)

from godb.

samonzeweb avatar samonzeweb commented on September 23, 2024

Thanks @derkan .

@tablecell, you can use LeftJoin (most useful for 0,1 or 1,1 relationship) ou InnerJoin . In last resort you can use a row statement : https://github.com/samonzeweb/godb/blob/master/dbtests/common/rawsql_tests.go

Please not that godb returns only 1 rowset, even with a join clause. It's not like ActiveRecord (Rails) or Entity Framework (.NET) whose return a graph a data. If you want something similar you have to do separate requests (if needed) ans rebuild a graph yourself.

from godb.

Related Issues (20)

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.