aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-06-03 10:19:45 +0100
committerMatthew Lemon <y@yulqen.org>2024-06-03 10:19:45 +0100
commitc113043073dea92c9c705a86064c05364aa6902e (patch)
tree352863a957263bacc595255142f9d3646a623540
parent609f6597f1a11cdf35b3ad2da588336226863047 (diff)
Rips out Postgres - but leaves migration files for now
- this does not yet remove the models - uses sqlite3 driver - changes the config based on sqlite3 - tests pass but no depth in investigating the models The sqlite3 database is going to be used for storing user data and tokens only - we are not going to store the models in a database at this point. If we want to start saving datamaps, datamaplines, returns and returnlines, etc, we will need the models but as of this commit the models are still in the code.
-rw-r--r--.gitignore1
-rw-r--r--cmd/dbasik-api/main.go27
-rw-r--r--go.mod2
-rw-r--r--go.sum4
4 files changed, 8 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index b4484d8..dc2cb75 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ bin/
.env
resources/test.xlsm
tags
+db.sqlite3
diff --git a/cmd/dbasik-api/main.go b/cmd/dbasik-api/main.go
index b4850f8..066c2e6 100644
--- a/cmd/dbasik-api/main.go
+++ b/cmd/dbasik-api/main.go
@@ -32,7 +32,7 @@ import (
"time"
"github.com/joho/godotenv"
- _ "github.com/lib/pq"
+ _ "github.com/mattn/go-sqlite3"
)
const version = "0.0.1"
@@ -42,12 +42,7 @@ const version = "0.0.1"
type config struct {
port int
env string
- db struct {
- dsn string
- maxOpenConns int
- maxIdleConns int
- maxIdleTime string
- }
+ db string
}
// This application struct holds the dependencies for our HTTP handlers, helpers and
@@ -70,12 +65,7 @@ func main() {
// Read the flags into the config struct. Defaults are provided if none given.
flag.IntVar(&cfg.port, "port", 5000, "API server port")
flag.StringVar(&cfg.env, "env", "development", "Environment (development|staging|production)")
- flag.StringVar(&cfg.db.dsn, "db-dsn", os.Getenv("DBASIK_DB_DSN"), "PostgreSQL DSN")
-
- //Read connection pool settings (explained in Configuring the pool in the book)
- flag.IntVar(&cfg.db.maxOpenConns, "db-max-open-conns", 25, "PostgreSQL max open connections")
- flag.IntVar(&cfg.db.maxIdleConns, "db-max-idle-conns", 25, "PostgreSQL max idle connections")
- flag.StringVar(&cfg.db.maxIdleTime, "db-max-idle-time", "15m", "PostgreSQL max connection idle time")
+ flag.StringVar(&cfg.db, "db-dsn", os.Getenv("DBASIK_DB_DSN"), "sqlite3 DSN")
flag.Parse()
@@ -118,19 +108,10 @@ func main() {
}
func openDB(cfg config) (*sql.DB, error) {
- db, err := sql.Open("postgres", cfg.db.dsn)
- if err != nil {
- return nil, err
- }
-
- // set up pool config
- db.SetMaxOpenConns(cfg.db.maxOpenConns)
- db.SetMaxIdleConns(cfg.db.maxIdleConns)
- duration, err := time.ParseDuration(cfg.db.maxIdleTime)
+ db, err := sql.Open("sqlite3", cfg.db)
if err != nil {
return nil, err
}
- db.SetConnMaxIdleTime(duration)
// create a context with a 5 second timeout
// if the database hasn't connected within this time, there is a problem
diff --git a/go.mod b/go.mod
index ccc5ca8..1210282 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.22.1
require (
github.com/joho/godotenv v1.5.1
- github.com/lib/pq v1.10.9
+ github.com/mattn/go-sqlite3 v1.14.16
github.com/tealeg/xlsx/v3 v3.3.6
)
diff --git a/go.sum b/go.sum
index 8ce66f5..8618675 100644
--- a/go.sum
+++ b/go.sum
@@ -11,8 +11,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
-github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
-github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
+github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/peterbourgon/diskv/v3 v3.0.1 h1:x06SQA46+PKIUftmEujdwSEpIx8kR+M9eLYsUxeYveU=