Skip to content

Commit

Permalink
make database handler public method
Browse files Browse the repository at this point in the history
  • Loading branch information
adonese committed Sep 21, 2022
1 parent e4dd524 commit 6df1a56
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ location /ws {
proxy_set_header Host $host;
}
```
This might not be needed, since we do in `ServeWs` endpoint.

### Notes about the database

There's no simple way of using a database.

4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Message struct {
IsDelivered bool `db:"is_delivered" json:"is_delivered,omitempty"`
}

func openDb() (*sqlx.DB, error) {
db, err := sqlx.Connect("sqlite3", "test.db")
func OpenDb(name string) (*sqlx.DB, error) {
db, err := sqlx.Connect("sqlite3", name)
if err != nil {
log.Printf("error in opening db: %v", err)
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
_ "github.com/mattn/go-sqlite3"
)

var testDb, _ = openDb()
var testDb, _ = OpenDb("test.db")

func TestChat_insert(t *testing.T) {

Expand Down

0 comments on commit 6df1a56

Please sign in to comment.