I got an error connecting my edgedb database on my go server

476 Views Asked by At

I was working on an example project with edgedb as my database. I ran into some syntax errors but I sorted and fixed all of it and it ran smoothly for about 5 seconds. After that a panic message popped up.

    2023/02/13 22:13:04 edgedb.ClientConnectionFailedTemporarilyError: dial tcp 
    127.0.0.1:5656: connect: connection refused
    panic: edgedb.ClientConnectionFailedTemporarilyError: dial tcp 127.0.0.1:5656: connect: 
    connection refused

    goroutine 1 [running]:
    log.Panic({0xc00069df40?, 0xbd76b0?, 0xc0000320e8?})
        /snap/go/10030/src/log/log.go:388 +0x65
    main.Guard(...)
        /home/cyril/CODING/GOLANG/EdgeDB_Test/main.go:26
    main.main()
        /home/cyril/CODING/GOLANG/EdgeDB_Test/main.go:43 +0x18f
    exit status 2

I tried to change things but it did not work. The migration directory and both esdl files are empty. The edgedb.toml file only showed the version of edgedb. The go.mod & go.sum are my dependencies.

My main.go file looks like this:

    package main

    import (
        "context"
        "fmt"
        "log"
        "time"
        "net/http"

        "github.com/edgedb/edgedb-go"
        gearbox "github.com/gin-gonic/gin"
    )

    type User struct {
        ID   edgedb.UUID `edgedb:"id"`
        Name string      `edgedb:"name"`
        DOB  time.Time   `edgedb:"dob"`
    }

    var opts = edgedb.Options{Concurrency: 4}
    var c = context.Background()
    const url = "edgedb://edgedb@localhost/test";

    func Guard(err error) {
        if err != nil {
            log.Panic(err);
        }   
     }

    func main() {
        Gear := gearbox.Default();
        db, err := edgedb.CreateClientDSN(c, url, opts)
        Guard(err)
        defer db.Close()

        err = db.Execute(c, `
            CREATE TYPE User {
                CREATE REQUIRED PROPERTY name -> str;
                CREATE PROPERTY dob -> datetime;
               }
        `)
         Guard(err);


        var inserted struct{ id edgedb.UUID }
        err = db.QuerySingle(c, `
            INSERT User {
                name := <str>$0,
                dob := <datetime>$1
            }
        `, &inserted, "Bob", time.Date(1984, 3, 1, 0, 0, 0, 0, time.UTC))
        Guard(err);
        var users []User
        args := map[string]interface{}{"name": "Bob"}
        query := "SELECT User {name, dob} FILTER .name = <str>$name"
        err = db.Query(c, query, &users, args)
        Guard(err);
        Gear.GET("/", func (ctx *gearbox.Context) {
            ctx.JSON(http.StatusOK, gearbox.H{
                "message":users,
            })
        })
        fmt.Println(users)

        log.Fatalln(Gear.Run(":7000"))
    }

I don't know why the panic shows up. It repeatedly came for all 7 tries I did.``

0

There are 0 best solutions below