Coder Social home page Coder Social logo

scaffold's People

Contributors

boourns avatar carsonb avatar iamkevb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scaffold's Issues

list of pains

@iamkevb

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.

  1. Being directly tied to SQLite will definitely limit it's popularity.

  2. 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:

  • Database already exists with table 'A' already created. One migration runs on startup, CreateTableA.
  • I want to add a column 'foo' to table 'A'.
  • I add column foo to the struct A and regenerate the scaffold a_sql. This updates the CreateTableA function to also create column foo.
  • Since the first migration already ran, when I start the app and migrate the database nothing happens. SQL table still missing column foo.
  • I add a second migration, AddFooToTableA that adds column foo to table A.
  • I restart the application, column foo gets succesfully added since the second migration has never run.
  • I delete my database (say, it was development)
  • I restart the application. First migration runs, adding table A including column foo. Second migration runs, column foo already added, and the second migration fails.
  1. 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.

  2. Query interface does not support more complex concepts like grouping

  3. Maybe scaffold should become a child directory of dblib since the two are intertwined, and possibly more intertwined as we go?

Move from 100% generated to generated definition / library implementation

@iamkevb

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:

  • reduce footprint of generated code
  • make it easier to implement Dialects / different database engines
  • make it easier to register and extend with Hooks like AfterCreate, BeforeCommit, etc etc. This may not be worth the complexity but would be useful.

Downsides:

  • definitely worried about suddenly having to model all of SQL in Go

json tag on struct field confuses sql type finder

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

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.