Comments (4)
@wijayaerick You can use standard table sql aliasing. For instance:
client := Clients.AS("client")
and then use aliased table instead of Clients
:
stmt := SELECT(client.AllColumns).FROM(client)
Or you can tag the fields. But you should use alias
tag instead of db
.
Sample usage can be seen here: https://github.com/go-jet/jet/wiki/Query-Result-Mapping-(QRM)#tagging-model-files
For example:
type Client struct {
ID uuid.UUID `alias:"clients.id"`
CreatedAt time.Time `alias:"clients.created_at"`
UpdatedAt time.Time `alias:"clients.updated_at"`
Username string `alias:"clients.username"`
}
Future version will add support for customizing generated model files(like names and types).
Is the additional 's' in the name, the only reason why you didn't want to use generated model files?
from jet.
@go-jet Thank you for the suggestion. Using empty alias does the trick; it removes the table name prefix in columns and still preserve table name in FROM statement.
The reason I'm using my own model Struct is because I have methods defined in my models, for example func NewModel(..) *Model, func (m *Model) IsSomething() bool, etc..
from jet.
@wijayaerick If that's the case you can embed generated model struct into your custom model struct. For instance:
package mymodel
import ".../model"
struct Client struct {
model.Clients
}
func (c Client) isSomething() bool {
return c.Username != ""
}
With this approach you don't need to change SQL query for scan to work.
from jet.
Haven't thought about using embedding. Yes, that should work well for me. Thank you for your help. Also this is a great project and I'm looking forward to future development of this project.
from jet.
Related Issues (20)
- Add support for JSON Processing Functions
- [Question] How to populate nested "entities" that require self-join HOT 13
- Multiple database types support HOT 3
- How to generate table names plural and use CUSTOM models in singular? HOT 7
- [Question] Incremental filling of destination slice/struct HOT 4
- Control a destination of generator/postgres.GenerateDSN HOT 4
- Auto type Casting is wrong for custom type HOT 1
- UPDATE dynamic query. HOT 2
- Remove table name from columns alias HOT 3
- ErrNoRows not returned on INSERT ON CONFLICT DO UPDATE WHERE... HOT 3
- Add some model functins for auto insert or update HOT 1
- It would be nice to allow internal types for building based on user input HOT 3
- Support for reading from schema file instead of dsn HOT 2
- Custom Column Type HOT 3
- Additional select field changes record count. HOT 6
- Scan into a map. HOT 1
- Inject "AS OF SYSTEM TIME" into FROM clause HOT 2
- Use CTE value for query offset
- character varying = typeid error: Recipe `jet` failed on line 52 with exit code 1 HOT 3
- Support `OF` in locking clause HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jet.