Skip to content

Commit

Permalink
feat: add postgres support (fixes #165) (#223)
Browse files Browse the repository at this point in the history
This PR introduce a new flag --db-uri to define a way to specify where to store the db (either locally using `file:` schema, or via `postgres:` schema)

> the database uri to store the connection data database uri (by default, we'll use sqlite3 under storages/whatsapp.db). database uri --db-uri <string> | example: --db-uri="file:storages/whatsapp.db?_foreign_keys=off or postgres://user:password@localhost:5432/whatsapp"`)

Fixes #163
  • Loading branch information
AlmogBaku authored Jan 20, 2025
1 parent 90be808 commit 93f42ec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 102 deletions.
2 changes: 2 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html/v2"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -50,6 +51,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&config.WhatsappWebhook, "webhook", "w", config.WhatsappWebhook, `forward event to webhook --webhook <string> | example: --webhook="https://yourcallback.com/callback"`)
rootCmd.PersistentFlags().StringVarP(&config.WhatsappWebhookSecret, "webhook-secret", "", config.WhatsappWebhookSecret, `secure webhook request --webhook-secret <string> | example: --webhook-secret="super-secret-key"`)
rootCmd.PersistentFlags().BoolVarP(&config.WhatsappAccountValidation, "account-validation", "", config.WhatsappAccountValidation, `enable or disable account validation --account-validation <true/false> | example: --account-validation=true`)
rootCmd.PersistentFlags().StringVarP(&config.DBURI, "db-uri", "", config.DBURI, `the database uri to store the connection data database uri (by default, we'll use sqlite3 under storages/whatsapp.db). database uri --db-uri <string> | example: --db-uri="file:storages/whatsapp.db?_foreign_keys=off or postgres://user:password@localhost:5432/whatsapp"`)
}

func runRest(_ *cobra.Command, _ []string) {
Expand Down
2 changes: 1 addition & 1 deletion src/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
PathMedia = "statics/media"
PathStorages = "storages"

DBName = "whatsapp.db"
DBURI = "file:storages/whatsapp.db?_foreign_keys=off"

WhatsappAutoReplyMessage string
WhatsappWebhook string
Expand Down
1 change: 1 addition & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/gofiber/template/html/v2 v2.1.2
github.com/gofiber/websocket/v2 v2.2.1
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.24
github.com/sirupsen/logrus v1.9.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
Expand Down
Loading

0 comments on commit 93f42ec

Please sign in to comment.