Json-schema based database rows to arbitrary struct scanner generation with Go (golang). It is based on database/sql so it works with all database drivers
Whenever a bootstrap is required for a project we are hustling with creating the required folder, files, databases, roles/users schemas, sequences, tables, constraints, extensions types etc...
This package aims to ease that pain
JSON Schema specifies a JSON-based format to define the structure of your data for various cases, like validation, documentation, and interaction control. A JSON Schema provides a contract for the JSON data required by a given application, and how that data can be modified.
TLDR: here is an example twitter.json
Right here twitter/models/account_rowscanner
package models
import "database/sql"
func (a *Account) RowsScan(rows *sql.Rows, dest interface{}) error {
if rows == nil {
return nil
}
var records []*Account
for rows.Next() {
m := NewAccount()
err := rows.Scan(
&m.ID,
&m.ProfileID,
&m.Password,
&m.URL,
&m.PasswordStatusConstant,
&m.Salt,
&m.EmailAddress,
&m.EmailStatusConstant,
&m.StatusConstant,
&m.CreatedAt,
)
if err != nil {
return err
}
records = append(records, m)
}
if err := rows.Err(); err != nil {
return err
}
*(dest.(*[]*Account)) = records
return nil
}