Documentation ¶
Overview ¶
Example (Sqlite3) ¶
package main import ( "context" "fmt" "github.com/Breeze0806/go-etl/config" "github.com/Breeze0806/go-etl/element" "github.com/Breeze0806/go-etl/storage/database" "github.com/Breeze0806/go-etl/storage/database/sqlite3" ) func testJSONFromString(s string) *config.JSON { json, err := config.NewJSONFromString(s) if err != nil { panic(err) } return json } type TableParam struct { *database.BaseParam } func NewTableParam() *TableParam { return &TableParam{ BaseParam: database.NewBaseParam(sqlite3.NewTable(database.NewBaseTable("", "", "test")), nil), } } func (t *TableParam) Query(_ []element.Record) (string, error) { return "select * from test", nil } func (t *TableParam) Agrs(_ []element.Record) ([]interface{}, error) { return nil, nil } type FetchHandler struct { } func (f *FetchHandler) OnRecord(r element.Record) error { fmt.Println(r) return nil } func (f *FetchHandler) CreateRecord() (element.Record, error) { return element.NewDefaultRecord(), nil } func main() { fmt.Println("strat") db, err := database.Open("sqlite3", testJSONFromString(`{"url":"E:\\projects\\sqlite3\\test.db"}`)) if err != nil { fmt.Printf("open fail. err: %v", err) return } defer db.Close() err = db.FetchRecord(context.TODO(), NewTableParam(), &FetchHandler{}) if err != nil { fmt.Printf("fetchRecord fail. err: %v", err) return } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
URL string `json:"url"` // Database URL, including the database address and other database parameters
}
Config is the Sqlite3 configuration
type Dialect ¶
type Dialect struct{}
Dialect represents the database dialect for PostgreSQL
type Field ¶
type Field struct { *database.BaseField database.BaseConfigSetter }
Field - Represents a field in a database table.
type FieldType ¶
type FieldType struct { *database.BaseFieldType // contains filtered or unexported fields }
FieldType - Represents the type of a field.
func NewFieldType ¶
func NewFieldType(typ database.ColumnType) *FieldType
NewFieldType - Creates a new field type.
func (*FieldType) IsSupported ¶
IsSupported - Indicates whether parsing is supported for a specific type.
type Scanner ¶
type Scanner struct { database.BaseScanner // contains filtered or unexported fields }
Scanner - A scanner used for reading data based on the column type.
func NewScanner ¶
NewScanner - Generates a scanner based on the column type.
type Source ¶
type Source struct { *database.BaseSource // Basic data source // contains filtered or unexported fields }
Source postgres refers to the PostgreSQL data source
func (*Source) ConnectName ¶
ConnectName is the connection information for the Sqlite3 data source
type Table ¶
type Table struct { *database.BaseTable database.BaseConfigSetter }
Table represents a Sqlite3 table.
func NewTable ¶
NewTable creates a new Sqlite3 table. Note that at this point, the schema parameter in BaseTable refers to the schema name, instance is the database name, and name is the table name.
func (*Table) ExecParam ¶
ExecParam retrieves execution parameters, where the copy in parameter mode has been registered.
func (*Table) ShouldOneByOne ¶
ShouldOneByOne specifies whether to retry one operation at a time.
func (*Table) ShouldRetry ¶
ShouldRetry determines whether a retry is necessary.