boourns / scaffold Goto Github PK
View Code? Open in Web Editor NEWcode generator for go
code generator for go
what I'm currently thinking about how to use generics, let me know what you think
this is non-compilable pseudocode for now
// Model interface is provided by the scaffold library
type Model interface {
// columns returns a map of SQL column names to pointers to the field
Columns() map[string]interface{}
}
// input struct to scaffold, user writes this
type Person struct {
ID int16
Name string
}
// generated code defines the table and calls into the scaffold library
func (p *Person) Columns() map[string]interface{} {
return map[string]interface{}{
"ID": &p.ID,
"Name": &p.Name,
}
}
// this function is still nicer to use than the library
func SelectPerson(db dbutil.Queryable, conditions, vars) []Person {
return scaffold.Select[Person](db, conditions, vars)
}
Along with Columns
there could be a Schema
generated that the scaffold library knows how to convert to, say, a CREATE TABLE statement, but I'm not sure how to do this without accepting that we're modelling the entire SQL language within Go (ala GORM).
The goals of the approach would maybe be:
Downsides:
All the following should work with scaffold:
UpdatedAt time.Time `sqlType:"DATETIME" json:"updatedAt"`
UpdatedAt time.Time `json:"updatedAt" sqlType:"DATETIME"`
UpdatedAt time.Time `json:"updatedAt"`
UpdatedAt time.Time
Opening an issue to track major issues with the current version of scaffold that could be solved either now or when generics land. Trying to focus on just the issues without solutioning. I'm also listing some issues that are actually dblib issues.
Being directly tied to SQLite will definitely limit it's popularity.
I run into an issue where migrations can only run once, and if the database is cleared, the migration will fail. The order of events is:
CreateTableA
.foo
to the struct A and regenerate the scaffold a_sql
. This updates the CreateTableA
function to also create column foo.foo
.AddFooToTableA
that adds column foo to table A.Query interface is not type-safe and is not really discoverable. Remembering exactly what text to put into the conditions and joins is a bit tough. This is a pain but at the same time I'm worried the cure might be worse than the ailment.
Query interface does not support more complex concepts like grouping
Maybe scaffold
should become a child directory of dblib
since the two are intertwined, and possibly more intertwined as we go?
It would be nice for the database to protect against NULL values in columns, and scaffold should make that the default.
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.