aboutsummaryrefslogtreecommitdiff
path: root/pkg/db
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-12 02:52:22 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-12 02:53:52 +0300
commitd05ea66f4bbcf0cc5c8908f3435c68de1b070fa1 (patch)
tree7c7a769206646f2b81a0eda0680f0be5033a4197 /pkg/db
Начальная версияv0.0.1
Diffstat (limited to 'pkg/db')
-rw-r--r--pkg/db/config.go5
-rw-r--r--pkg/db/db.go18
2 files changed, 23 insertions, 0 deletions
diff --git a/pkg/db/config.go b/pkg/db/config.go
new file mode 100644
index 0000000..4df38f0
--- /dev/null
+++ b/pkg/db/config.go
@@ -0,0 +1,5 @@
+package db
+
+type Config struct {
+ DSN string `yaml:"dsn"`
+}
diff --git a/pkg/db/db.go b/pkg/db/db.go
new file mode 100644
index 0000000..8b7c47c
--- /dev/null
+++ b/pkg/db/db.go
@@ -0,0 +1,18 @@
+package db
+
+import (
+ "database/sql"
+
+ "github.com/uptrace/bun"
+ "github.com/uptrace/bun/dialect/pgdialect"
+ "github.com/uptrace/bun/driver/pgdriver"
+)
+
+// dsn := "postgres://postgres:@localhost:5432/test?sslmode=disable"
+// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
+
+func New(config *Config) *bun.DB {
+ sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(config.DSN)))
+
+ return bun.NewDB(sqldb, pgdialect.New())
+}