Code Monkey home page Code Monkey logo

Comments (4)

vmihailenco avatar vmihailenco commented on June 24, 2024

I am building model too and it has everything you mentioned :) But it is not ready yet. #96 is what I already have and it can already do simple queries - https://github.com/go-pg/pg/blob/feature/pg-v4/db_test.go#L176-L191. Any help is appreciated but code is not documented (but it should be clean and readable).

from pg.

greenpart avatar greenpart commented on June 24, 2024

Great! Hope your model layer will fit my requirements, but now I'm bound to existing codebase.

Anyway, what do you think about opening in terms of layers?

I've inspected code changes on master and found that index became unexported. It's great to know field depth as I need only top level fields. To achieve this we can define:

func (f *field) IsTopLevel() bool {
    return len(f.index) == 1
}

With this func we can iterate through fields.List and filter top level fields. But index values would be required someday too. So, I'm for making it exported. And I still need a way to get fields. Maybe something like this?

func FieldsForType(typ reflect.Type) fields {
    return structs.Fields(typ)
}

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

If you are bound to existing codebase then it is easier to just fork the lib and export whatever you need since it is very unlikely that v3 will receive big updates.

Anyway, what do you think about opening in terms of layers?

In v4 I plan to export those API in a subpackage so it does not clatter main API, e.g.:

import "gopkg.in/pg.v4/orm"

article := &MyArticle{}
table := orm.Tables.Get(reflect.TypeOf(article))
for _, field := range table.Fields {
    fmt.Println(field.Name)
    fmt.Println(field.GetValue(article)) // returns reflect.Value
}

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

This info is now exported in v4. You can start from reading Table definition https://godoc.org/gopkg.in/pg.v4/orm#Table

from pg.

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.