codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.62k stars 343 forks source link

EMBEDDING THE SQL ENGINE IN YOUR APPLICATION #1122

Closed hajsf closed 2 years ago

hajsf commented 2 years ago

Trying to test the example mentioned here and wrote the below:

package main

import (
    "log"

    "github.com/codenotary/immudb/embedded/sql"
    "github.com/codenotary/immudb/embedded/store"
)

func main() {
    catalogStore, err := store.Open("catalog", store.DefaultOptions())
    if err != nil {
        log.Fatal(err)
    }

    dataStore, err := store.Open("sqldata", store.DefaultOptions())
    if err != nil {
        log.Fatal(err)
    }

    engine, err := sql.NewEngine(catalogStore, dataStore, []byte("sql"))
    if err != nil {
        log.Fatal(err)
    }

    _, err = engine.ExecStmt("CREATE DATABASE db1")
    if err != nil {
        log.Fatal(err)
    }

    _, err = engine.ExecStmt("USE DATABASE db1")
    if err != nil {
        log.Fatal(err)
    }

    _, err = engine.ExecStmt("CREATE TABLE journal (id INTEGER, date VARCHAR, creditaccount INTEGER, debitaccount INTEGER amount INTEGER, description VARCHAR, PRIMARY KEY id)")
    if err != nil {
        log.Fatal(err)
    }

    r, err := engine.QueryStmt("SELECT id, date, creditaccount, debitaccount, amount, description FROM journal WHERE amount > @value", map[string]interface{}{"value": 100}, true)

    for {
        row, err := r.Read()
        if err == sql.ErrNoMoreRows {
            break
        }
        if err != nil {
            log.Fatal(err)
        }

        // do something with row.Values
    }
}

But I'm getting errors at: engine.ExecStmt undefined (type *sql.Engine has no field or method ExecStmt)compiler[MissingFieldOrMethod](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#MissingFieldOrMethod) and too many arguments in call to sql.NewEngine have (*store.ImmuStore, *store.ImmuStore, []byte) want (*store.ImmuStore, *sql.Options)compiler[WrongArgCount](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#WrongArgCount)

jeroiraz commented 2 years ago

Example upgraded to work with latest immudb version 1.2.4 (https://docs.immudb.io/master/develop/embedding.html#embedding-immudb-key-value-store)