jamillosantos / go-ceous Goto Github PK
View Code? Open in Web Editor NEWAn ORM experiment in GO
License: MIT License
An ORM experiment in GO
License: MIT License
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
.
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.
Briefing
The Queries and Stores are not using the default connection by default. For every initialization, we have to set the connection.
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.
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.