generated from alecodes/base-template
also refactor public and internal api to support transaction between multiple methods #2
48 lines
842 B
Go
48 lines
842 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
_ "modernc.org/sqlite"
|
|
|
|
synchronizator "git.alecodes.page/alecodes/synchronizator/pkg"
|
|
)
|
|
|
|
type PokeApi struct{}
|
|
|
|
func (pokeApi *PokeApi) ToNode() (string, []byte, error) {
|
|
return "POKEAPI", nil, nil
|
|
}
|
|
|
|
func (pokeApi *PokeApi) FromNode(_class string, name string, metadata []byte) error {
|
|
if _class != "POKEAPI" {
|
|
return fmt.Errorf("invalid class %s", _class)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
connection, err := sql.Open("sqlite", "db.sql")
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
|
|
return
|
|
}
|
|
|
|
defer connection.Close()
|
|
|
|
opts := synchronizator.DefaultOptions
|
|
// opts.Log_level = synchronizator.DEBUG
|
|
opts.DANGEROUSLY_DROP_TABLES = true
|
|
|
|
sync, err := synchronizator.New(connection, opts)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
|
|
return
|
|
}
|
|
|
|
pokeApi := &PokeApi{}
|
|
sync.NewPlatform(pokeApi)
|
|
}
|