generated from alecodes/base-template
wip: implementing db initialization
This commit is contained in:
parent
ffd3c2014e
commit
140eef1fab
11 changed files with 451 additions and 0 deletions
61
examples/usage.go
Normal file
61
examples/usage.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
synchronizator "git.alecodes.page/alecodes/synchronizator/pkg"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
type ProgrammingLanguage struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type Library struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type (
|
||||
BelognsTo struct{}
|
||||
IsSame struct{}
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
sync.RegisterNodeClass(Library{})
|
||||
|
||||
// collection, err := sync.NewCollection(ProgrammingLanguage{Name: "foo"})
|
||||
express, err := sync.NewNode("ExpressJS", Library{Version: "v22"})
|
||||
flask, err := sync.NewNode("Flask", Library{Version: "v22"})
|
||||
relation, err := sync.AddRelation(express.Id, BelognsTo{}, flask.Id)
|
||||
// relation, err := express.AddRelation(BelognsTo{}, flask.Id)
|
||||
// node, err := sync.GetNode(1)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
return
|
||||
}
|
||||
// fmt.Printf("\n%+v\n", collection)
|
||||
fmt.Printf("\n%+v\n", express)
|
||||
fmt.Printf("\n%+v\n", flask)
|
||||
fmt.Printf("\n%+v\n", relation)
|
||||
}
|
||||
Reference in a new issue