This repository has been archived on 2025-05-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
synchronizator-go/examples/usage.go
aleidk 01086d12c9 feat: implement platform handler creation
also refactor public and internal api to support transaction between
multiple methods

#2
2024-11-18 16:51:09 -03:00

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)
}