Giter Club home page Giter Club logo

go-ceous's People

Contributors

jamillosantos avatar

Watchers

 avatar  avatar  avatar

go-ceous's Issues

Pointer to embedded fields break inserts

Briefing

Let's say we have this model:

type Response struct {
    ceous.Embedded
    Status int `ceous:"status"
}

type Call struct {
    ceous.Model `tableName:"calls"`
    Response *Response `ceous:"response"`
}

The generated code for the model:

// Value returns the value from a field given its column name.
func (model *Call) Value(name string) (interface{}, error) {
	switch name {
	case "response_status_code":
		return model.Response.StatusCode, nil
	case "response_headers":
		return model.Response.Headers, nil
	case "response_body":
		return model.Response.Body, nil
	case "tags":
		return model.Tags, nil
// this methods continue ......
}

Problem

By the Value method implementation is possible to see that if model.Response can be nil and break the whole thing.

ColumnAddress has the same problem:

func (model *Call) ColumnAddress(name string) (interface{}, error) {
    switch name {
    case "response_status_code":
        return &model.Response.StatusCode, nil
    case "response_headers":
        return &model.Response.Headers, nil
    case "response_body":
        return &model.Response.Body, nil
    // ...
}

When trying to Insert without specifying the right fields, for example, it might panic because Response can be nil.

Implement default scenarios

Briefing

Let's say the system has a Users. Users can be deleted, but not really. Instead, the system soft deletes them to keep who did some actions. So, for the UserQuery deleted users should always be filtered out. For those cases would be nice to have some sort of "default scenario".

Default scenarios are filters applied to the query as soon as it gets created. It would work as a filter method that is run whenever the Query is initialized.

Of course, we would have an option to disable it.

The default connection is not set

Briefing

The Queries and Stores are not using the default connection by default. For every initialization, we have to set the connection.

Updating and inserting models with embedded fields

Briefing

This description seems like #24. But, is a different issue. Follow on.

Let's say we have this model:

type Response struct {
    ceous.Embedded
    Status int `ceous:"status"
}

type Call struct {
    ceous.Model `tableName:"calls"`
    Response Response `ceous:"response"`
}

The generated code for the model:

// Value returns the value from a field given its column name.
func (model *Call) Value(name string) (interface{}, error) {
	switch name {
	case "response_status_code":
		return model.Response.StatusCode, nil
	case "response_headers":
		return model.Response.Headers, nil
	case "response_body":
		return model.Response.Body, nil
	case "tags":
		return model.Tags, nil
// this methods continue ......
}

Problem

When inserting the model without specifying any fields we get:

sql: converting argument $2 type: unsupported type models.Response, a struct

What happens is that the Call.Request field is considered to be a type and tries to be persisted in the database. But, it is a struct which has fields.

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.