driver.go raw

   1  package sqlite_wrapper
   2  
   3  import (
   4  	"database/sql"
   5  
   6  	"github.com/mattn/go-sqlite3"
   7  )
   8  
   9  const Sqlite3WrapperDriverName = "sqlite3_wrapper"
  10  
  11  func init() {
  12  	// We need to set the temp_store setting on every connection, including
  13  	// those that are implicitly opened by Go's database/sql package.
  14  	// Unfortunately, this setting cannot be provided in the DSN; therefore
  15  	// we execute the PRAGMA statement in the sqlite3's connection hook.
  16  	sql.Register(Sqlite3WrapperDriverName, &sqlite3.SQLiteDriver{
  17  		ConnectHook: func(conn *sqlite3.SQLiteConn) error {
  18  			_, err := conn.Exec("PRAGMA temp_store = MEMORY", nil)
  19  			return err
  20  		},
  21  	})
  22  }
  23