Documentation
¶
Overview ¶
Example (GenerateWithQuery) ¶
package main
import (
"context"
"fmt"
"github.com/Jumpaku/schenerate/files"
"github.com/Jumpaku/schenerate/sqlite3"
)
func main() {
type T struct {
Name string `db:"name"`
Age int64 `db:"age"`
}
q, err := sqlite3.Open("db.sqlite")
if err != nil {
panic(err)
}
defer q.Close()
err = sqlite3.GenerateWithQuery(context.Background(), q,
`SELECT 'A' AS "name", 1 AS "age" UNION SELECT 'B' AS "name", 2 AS "age"`,
nil,
func(w *files.Writer, rows []T) error {
w.Add("records.txt")
for _, row := range rows {
// do something with a row
fmt.Fprintf(w, "%+v\n", row)
}
return nil
},
)
if err != nil {
panic(err)
}
}
Example (GenerateWithSchema) ¶
package main
import (
"context"
"fmt"
"github.com/Jumpaku/schenerate/files"
"github.com/Jumpaku/schenerate/sqlite3"
)
func main() {
q, err := sqlite3.Open("db.sqlite")
if err != nil {
panic(err)
}
defer q.Close()
err = sqlite3.GenerateWithSchema(context.Background(), q,
[]string{"Table"},
func(w *files.Writer, schemas sqlite3.Schemas) error {
for _, schema := range schemas {
// do something with schemas
w.Add(schema.Name)
fmt.Fprintf(w, "%+v\n", schema.Name)
}
return nil
},
)
if err != nil {
panic(err)
}
}
Index ¶
- func GenerateWithQuery[RecordStruct any](ctx context.Context, q queryer, stmt string, params []any, ...) error
- func GenerateWithSchema(ctx context.Context, q queryer, tables []string, generator GeneratorWithSchema) error
- func Open(dsn string) (queryer, error)
- func QueryRows[RecordStruct any](ctx context.Context, q queryer, stmt string, params []any) (records []RecordStruct, err error)
- type Column
- type ForeignKey
- type ForeignKeyReference
- type GeneratorWithQuery
- type GeneratorWithSchema
- type Index
- type IndexKeyElem
- type IndexOrigin
- type Schema
- type Schemas
- type Table
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateWithQuery ¶ added in v0.0.5
func GenerateWithSchema ¶
func GenerateWithSchema(ctx context.Context, q queryer, tables []string, generator GeneratorWithSchema) error
Types ¶
type ForeignKey ¶
type ForeignKey struct {
Key []string
Reference ForeignKeyReference
}
type ForeignKeyReference ¶
type GeneratorWithQuery ¶ added in v0.0.5
type GeneratorWithSchema ¶ added in v0.0.5
type Index ¶
type Index struct {
Name string
Origin IndexOrigin
Unique bool
Key []IndexKeyElem
}
type IndexKeyElem ¶
type IndexOrigin ¶
type IndexOrigin string
IndexOrigin is a type for the origin of an index. https://www.sqlite.org/pragma.html#pragma_index_list > "c" if the index was created by a CREATE INDEX statement, "u" if the index was created by a UNIQUE constraint, or "pk" if the index was created by a PRIMARY KEY constraint.
const ( IndexOriginPrimaryKey IndexOrigin = "pk" IndexOriginCreateIndex IndexOrigin = "c" IndexOriginUniqueConstraint IndexOrigin = "u" )
Click to show internal directories.
Click to hide internal directories.