Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions dialect_sqlite.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//go:build sqlite
// +build sqlite

package pop

import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"io"
"net/url"
Expand All @@ -21,8 +20,6 @@ import (
"github.com/gobuffalo/pop/v6/internal/defaults"
"github.com/gobuffalo/pop/v6/logging"
"github.com/jmoiron/sqlx"
"github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3" // Load SQLite3 CGo driver
)

const nameSQLite3 = "sqlite3"
Expand All @@ -43,6 +40,15 @@ type sqlite struct {
smGil *sync.Mutex
}

func requireSQLite3() error {
for _, driverName := range sql.Drivers() {
if driverName == nameSQLite3 {
return nil
}
}
return errors.New("sqlite3 support was not compiled into the binary")
}

func (m *sqlite) Name() string {
return nameSQLite3
}
Expand Down Expand Up @@ -263,6 +269,10 @@ func (m *sqlite) TruncateAll(tx *Connection) error {
}

func newSQLite(deets *ConnectionDetails) (dialect, error) {
err := requireSQLite3()
if err != nil {
return nil, err
}
deets.URL = fmt.Sprintf("sqlite3://%s", deets.Database)
cd := &sqlite{
gil: &sync.Mutex{},
Expand Down Expand Up @@ -328,5 +338,13 @@ func finalizerSQLite(cd *ConnectionDetails) {
}

func newSQLiteDriver() (driver.Driver, error) {
return new(sqlite3.SQLiteDriver), nil
err := requireSQLite3()
if err != nil {
return nil, err
}
db, err := sql.Open(nameSQLite3, ":memory:?cache=newSQLiteDriver_temporary")
if err != nil {
return nil, err
}
return db.Driver(), db.Close()
}
23 changes: 0 additions & 23 deletions dialect_sqlite_shim.go

This file was deleted.

8 changes: 8 additions & 0 deletions dialect_sqlite_tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build sqlite
// +build sqlite

package pop

import (
_ "github.com/mattn/go-sqlite3" // Load SQLite3 CGo driver
)