mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/implement wss routes (#1196)
* feat(database): create schema for hway and motr * fix(gateway): correct naming inconsistencies in handlers * build: update schema file to be compatible with postgresql syntax * fix: update schema to be compatible with PostgreSQL syntax * chore: update query_hway.sql to follow sqlc syntax * ```text refactor: update query_hway.sql for PostgreSQL and sqlc ``` * feat: add vaults table to store encrypted data * refactor: Update vaults table schema for sqlc compatibility * chore(deps): Upgrade dependencies and add pgx/v5 * refactor(Makefile): move sqlc generate to internal/models * docs(foundations): remove outdated pages * chore(build): add Taskfile for build tasks * refactor(embed): move embed files to internal package * docs: add documentation for Cosmos SDK ORM
This commit is contained in:
+9
-5
@@ -39,7 +39,11 @@ func rootCmd() *cobra.Command {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
e, err := gateway.New(env, ipc)
|
||||
dbq, err := setupPostgresDB()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
e, err := gateway.New(env, ipc, dbq)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -56,10 +60,10 @@ func rootCmd() *cobra.Command {
|
||||
cmd.Flags().StringVar(&sonrAPIURL, "sonr-api-url", "localhost:1317", "Sonr API URL")
|
||||
cmd.Flags().StringVar(&sonrGrpcURL, "sonr-grpc-url", "localhost:9090", "Sonr gRPC URL")
|
||||
cmd.Flags().StringVar(&sonrRPCURL, "sonr-rpc-url", "localhost:26657", "Sonr RPC URL")
|
||||
cmd.Flags().StringVar(&psqlHost, "psql-host", "", "PostgresSQL Host")
|
||||
cmd.Flags().StringVar(&psqlUser, "psql-user", "", "PostgresSQL User")
|
||||
cmd.Flags().StringVar(&psqlPass, "psql-pass", "", "PostgresSQL Password")
|
||||
cmd.Flags().StringVar(&psqlDB, "psql-db", "", "PostgresSQL Database")
|
||||
cmd.Flags().StringVar(&psqlHost, "psql-host", "localhost", "PostgresSQL Host")
|
||||
cmd.Flags().StringVar(&psqlUser, "psql-user", "postgres", "PostgresSQL User")
|
||||
cmd.Flags().StringVar(&psqlPass, "psql-pass", "postgres", "PostgresSQL Password")
|
||||
cmd.Flags().StringVar(&psqlDB, "psql-db", "highway", "PostgresSQL Database")
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
config "github.com/onsonr/sonr/internal/config/hway"
|
||||
"github.com/onsonr/sonr/internal/models/drivers/hwayorm"
|
||||
)
|
||||
|
||||
// main is the entry point for the application
|
||||
@@ -35,3 +38,12 @@ func loadEnvImplFromArgs(args []string) (config.Hway, error) {
|
||||
}
|
||||
return env, nil
|
||||
}
|
||||
|
||||
func setupPostgresDB() (*hwayorm.Queries, error) {
|
||||
pgdsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", psqlHost, psqlUser, psqlPass, psqlDB)
|
||||
conn, err := pgx.Connect(context.Background(), pgdsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return hwayorm.New(conn), nil
|
||||
}
|
||||
|
||||
+20
-1
@@ -4,13 +4,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/pkg/vault/routes"
|
||||
_ "github.com/ncruces/go-sqlite3/driver"
|
||||
_ "github.com/ncruces/go-sqlite3/embed"
|
||||
"github.com/onsonr/sonr/cmd/motr/wasm"
|
||||
"github.com/onsonr/sonr/internal/config/motr"
|
||||
sink "github.com/onsonr/sonr/internal/models/sink/sqlite"
|
||||
vault "github.com/onsonr/sonr/pkg/vault/routes"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -52,3 +57,17 @@ func main() {
|
||||
vault.RegisterRoutes(e, config)
|
||||
wasm.ServeFetch(e)
|
||||
}
|
||||
|
||||
// NewDB initializes and returns a configured database connection
|
||||
func NewDB() (*sql.DB, error) {
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create tables
|
||||
if _, err := db.ExecContext(context.Background(), sink.SchemaMotrSQL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user