27+ results for 'lang:go db.SetMaxOpenConns(1) sqlite' (0 ms)

Not the results you expected?

db.go (https://github.com/matrix-org/go-neb.git) Go · 353 lines

41 return

42 }

43 if databaseType == "sqlite3" {

44 // Fix for "database is locked" errors

45 // https://github.com/mattn/go-sqlite3/issues/274

46 db.SetMaxOpenConns(1)

47 }

48 serviceDB = &ServiceDB{db: db, dialect: databaseType}

329 }

330

331 // GetSQLDb retrieves the SQL database instance of a ServiceDB and the dialect it uses (sqlite3 or postgres).

332 func (d *ServiceDB) GetSQLDb() (*sql.DB, string) {

333 return d.db, d.dialect

rel_store.go (https://github.com/github/orchestrator.git) Go · 249 lines

76 if relStore.backend == nil {

77 relStoreFile := filepath.Join(relStore.dataDir, raftStoreFile)

78 sqliteDB, _, err := sqlutils.GetSQLiteDB(relStoreFile)

79 if err != nil {

80 return nil, err

81 }

82 sqliteDB.SetMaxOpenConns(1)

83 sqliteDB.SetMaxIdleConns(1)

84 for _, query := range createQueries {

85 if _, err := sqliteDB.Exec(sqlutils.ToSqlite3Dialect(query)); err != nil {

86 return nil, err

87 }

88 }

89 relStore.backend = sqliteDB

90 log.Infof("raft: store initialized at %+v", relStoreFile)

91 }

conn.go (https://gitlab.com/github-cloud-corporation/dex) Go · 110 lines

59 db.SetMaxOpenConns(cfg.MaxOpenConnections)

60 dialect = gorp.PostgresDialect{}

61 case "sqlite3":

62 db, err = sql.Open("sqlite3", u.Host)

65 }

66 if u.Host == ":memory:" {

67 // NOTE(ericchiang): sqlite3 coordinates concurrent clients through file locks.

68 // In memory databases do not support concurrent calls. Limit the number of

69 // open connections to 1.

70 //

71 // See: https://www.sqlite.org/faq.html#q5

72 db.SetMaxOpenConns(1)

73 }

74 dialect = gorp.SqliteDialect{}

75 default:

76 return nil, errors.New("unrecognized database driver")

store.go (https://github.com/rancher/k3s.git) Go · 231 lines

13

14 "github.com/canonical/go-dqlite/internal/protocol"

15 _ "github.com/mattn/go-sqlite3" // Go SQLite bindings

16 )

17

42

43 // DefaultNodeStore creates a new NodeStore using the given filename to

44 // open a SQLite database, with default names for the schema, table and column

45 // parameters.

46 //

48 func DefaultNodeStore(filename string) (*DatabaseNodeStore, error) {

49 // Open the database.

50 db, err := sql.Open("sqlite3", filename)

51 if err != nil {

52 return nil, errors.Wrap(err, "failed to open database")

sqlite.go (https://github.com/sj14/dbbench.git) Go · 105 lines

10 )

11

12 // SQLite implements the bencher interface.

13 type SQLite struct {

20 )

21

22 // NewSQLite retruns a new SQLite bencher.

23 func NewSQLite(path string) *SQLite {

30

31 // Automatically creates the DB file if it doesn't exist yet.

32 db, err := sql.Open("sqlite3", fmt.Sprintf("%s?cache=shared", path))

33 if err != nil {

34 log.Fatalf("failed to open connection: %v\n", err)

35 }

36

37 db.SetMaxOpenConns(1)

38 p := &SQLite{db: db}

test_db.go (https://github.com/go-reform/reform.git) Go · 155 lines

9 "time"

10

11 sqlite3Driver "github.com/mattn/go-sqlite3"

12

13 "gopkg.in/reform.v1"

35

36 // register custom function "sleep" for context tests

37 if driver == "sqlite3" {

38 driver = "sqlite3_with_sleep"

43 return nsec, nil

44 }

45 sql.Register(driver, &sqlite3Driver.SQLiteDriver{

46 ConnectHook: func(conn *sqlite3Driver.SQLiteConn) error {

119

120 var version, sourceID string

121 if err = db.QueryRow("SELECT sqlite_version(), sqlite_source_id()").Scan(&version, &sourceID); err != nil {

122 log.Fatal(err)

123 }

db.go (https://github.com/jollheef/out-of-tree.git) Go · 335 lines

11 "time"

12

13 _ "github.com/mattn/go-sqlite3"

14

15 "code.dumpstack.io/tools/out-of-tree/config"

288

289 func openDatabase(path string) (db *sql.DB, err error) {

290 db, err = sql.Open("sqlite3", path)

291 if err != nil {

292 return

293 }

294

295 db.SetMaxOpenConns(1)

296

297 exists, _ := metaChkValue(db, versionField)

sqlite.go (https://bitbucket.org/depechebot/pyjamabot.git) Go · 289 lines

1 package sqlite

2

3 import (

29

30 // slowing this model down cause of this bug:

31 // https://github.com/mattn/go-sqlite3/issues/274

32 m.db.SetMaxOpenConns(1)

app.go (https://github.com/offen/offen.git) Go · 97 lines

14 "gorm.io/driver/mysql"

15 "gorm.io/driver/postgres"

16 "gorm.io/driver/sqlite"

17 "gorm.io/gorm"

18 "gorm.io/gorm/logger"

53 var d gorm.Dialector

54 switch c.Database.Dialect.String() {

55 case "sqlite3":

56 d = sqlite.Open(c.Database.ConnectionString.String())

72 gormDB, err = gorm.Open(d, &gorm.Config{

73 Logger: logger.Default.LogMode(logLevel),

74 DisableForeignKeyConstraintWhenMigrating: c.Database.Dialect.String() == "sqlite3",

75 })

76 return err

87 }

88

89 if c.Database.Dialect == "sqlite3" {

90 db, err := gormDB.DB()

91 if err != nil {

main.go (https://github.com/go-reform/reform.git) Go · 152 lines

15 _ "github.com/jackc/pgx/stdlib"

16 _ "github.com/lib/pq"

17 _ "github.com/mattn/go-sqlite3"

18

19 "gopkg.in/reform.v1"

57

58 // Use single connection so various session-related variables work.

59 // For example: "PRAGMA foreign_keys" for SQLite3, "SET IDENTITY_INSERT" for MS SQL, etc.

60 sqlDB.SetMaxIdleConns(1)

61 sqlDB.SetMaxOpenConns(1)

db.go (https://github.com/drone/autoscaler.git) Go · 70 lines

28 case "mysql":

29 db.SetMaxIdleConns(0)

30 case "sqlite3":

31 db.SetMaxOpenConns(1)

root.go (https://github.com/stephenafamo/docker-nginx-auto-proxy.git) Go · 98 lines

47

48 log.Println("Connecting to DB...")

49 db, err := sql.Open("sqlite3", "file::memory:?_fk=1&cache=shared&mode=memory")

50 if err != nil {

51 return err

52 }

53 db.SetMaxOpenConns(1)

54 defer db.Close()

55

sqlitePieceCompletion.go (https://github.com/yunionio/onecloud.git) Go · 55 lines

8

9 "github.com/anacrolix/torrent/metainfo"

10 _ "github.com/mattn/go-sqlite3"

11 )

12

13 type sqlitePieceCompletion struct {

14 db *sql.DB

15 }

17 var _ PieceCompletion = (*sqlitePieceCompletion)(nil)

18

19 func NewSqlitePieceCompletion(dir string) (ret *sqlitePieceCompletion, err error) {

20 p := filepath.Join(dir, ".torrent.db")

21 db, err := sql.Open("sqlite3", p)

sqlite.go (https://github.com/status-im/status-go.git) Go · 88 lines

1 package sqlite

2

3 import (

15 // https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA

16 kdfIterationsNumber = 3200

17 // WALMode for sqlite.

18 WALMode = "wal"

19 )

20

21 func openDB(path, key string) (*sql.DB, error) {

22 db, err := sql.Open("sqlite3", path)

23 if err != nil {

24 return nil, err

26

27 // Disable concurrent access as not supported by the driver

28 db.SetMaxOpenConns(1)

29

30 if _, err = db.Exec("PRAGMA foreign_keys=ON"); err != nil {

database.go (https://github.com/uber/kraken.git) Go · 46 lines

21

22 "github.com/jmoiron/sqlx"

23 _ "github.com/mattn/go-sqlite3" // SQL driver.

24 "github.com/pressly/goose"

25 )

26

27 // New creates a new locally embedded SQLite database.

28 func New(config Config) (*sqlx.DB, error) {

29 if err := osutil.EnsureFilePresent(config.Source, 0775); err != nil {

30 return nil, fmt.Errorf("ensure db source present: %s", err)

31 }

32 db, err := sqlx.Open("sqlite3", config.Source)

33 if err != nil {

34 return nil, fmt.Errorf("open sqlite3: %s", err)

sqlite.go (https://github.com/status-im/status-go.git) Go · 124 lines

52 }

53

54 db, err := sql.Open("sqlite3", path)

55 if err != nil {

56 return nil, err

60

61 // Disable concurrent access as not supported by the driver

62 db.SetMaxOpenConns(1)

63

64 if _, err = db.Exec("PRAGMA foreign_keys=ON"); err != nil {

sqlite.go (https://github.com/fnproject/fn.git) Go · 73 lines

16 func (sqliteHelper) Supports(scheme string) bool {

17 switch scheme {

18 case "sqlite3", "sqlite":

19 return true

20 }

38 }

39

40 func (sqliteHelper) CheckTableExists(tx *sqlx.Tx, table string) (bool, error) {

41 query := tx.Rebind(`SELECT count(*)

42 FROM sqlite_master

62 sqliteErr, ok := err.(sqlite3.Error)

63 if ok {

64 if sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique || sqliteErr.ExtendedCode == sqlite3.ErrConstraintPrimaryKey {

65 return true

66 }

db.go (https://github.com/status-im/status-go.git) Go · 159 lines

1 package sqlite

2

3 import (

40 }

41

42 // OpenInMemory opens an in memory SQLite database.

43 // Number of KDF iterations is reduced to 0.

44 func OpenInMemory() (*sql.DB, error) {

60 }

61

62 db, err := sql.Open("sqlite3", path)

63 if err != nil {

64 return nil, err

68

69 // Disable concurrent access as not supported by the driver

70 db.SetMaxOpenConns(1)

71

72 if _, err = db.Exec("PRAGMA foreign_keys=ON"); err != nil {

data.go (https://github.com/gabek/owncast.git) Go · 135 lines

46 }

47

48 db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?_cache_size=10000&cache=shared&_journal_mode=WAL", file))

49 db.SetMaxOpenConns(1)

50 _db = db

51

52 // Some SQLite optimizations

53 _, _ = db.Exec("pragma journal_mode = WAL")

54 _, _ = db.Exec("pragma synchronous = normal")

open.go (https://github.com/facebookincubator/magma.git) Go · 46 lines

20 _ "github.com/go-sql-driver/mysql"

21 _ "github.com/lib/pq"

22 _ "github.com/mattn/go-sqlite3"

23 )

24

26 MariaDriver = "mysql"

27 PostgresDriver = "postgres"

28 SQLiteDriver = "sqlite3"

29 )

30

31 // Open is a wrapper for sql.Open which sets the max open connections to 1

32 // for in memory sqlite3 dbs. In memory sqlite3 creates a new database

33 // on each connection, so the number of open connections must be limited

34 // to 1 for thread safety. Otherwise, there is a race condition between

sqlite.go (https://github.com/netsec-ethz/scion.git) Go · 122 lines

23 )

24

25 // NewSqlite returns a new SQLite backend opening a database at the given path. If

26 // no database exists a new database is be created. If the schema version of the

27 // stored database is different from schemaVersion, an error is returned.

28 func NewSqlite(path string, schema string, schemaVersion int) (*sql.DB, error) {

29 var err error

30 if path == "" {

31 return nil, serrors.New("Empty path not allowed for sqlite")

32 }

33 db, err := open(path)

sqlite.go (https://github.com/Dentrax/GMDB.git) Go · 61 lines

16

17 "github.com/jmoiron/sqlx"

18 _ "github.com/mattn/go-sqlite3"

19 )

20

34 }

35

36 db.SetMaxOpenConns(1)

37

38 var engine Driver = Sqlite

sql_init.go (https://github.com/fnproject/flow.git) Go · 120 lines

16

17 var tables = map[string][]string{

18 "sqlite3": {

19 `CREATE TABLE IF NOT EXISTS events (

20 actor_name varchar(255) NOT NULL,

63 driver := url.Scheme

64 switch driver {

65 case "mysql", "sqlite3":

66 default:

67

69 }

70

71 if driver == "sqlite3" {

72 dir := filepath.Dir(url.Path)

73 err := os.MkdirAll(dir, 0755)

cmdutils.go (https://github.com/dude333/rapina.git) Go · 118 lines

36 }

37 connStr := "file:" + dataDir + "/rapina.db?cache=shared&mode=rwc&_journal_mode=WAL&_busy_timeout=5000"

38 db, err = sql.Open("sqlite3", connStr)

39 if err != nil {

40 return db, errors.Wrap(err, "database open failed")

41 }

42 db.SetMaxOpenConns(1)

43

44 return

db.go (https://github.com/bakape/hydron.git) Go · 83 lines

13 "github.com/bakape/hydron/files"

14 _ "github.com/lib/pq"

15 _ "github.com/mattn/go-sqlite3"

16 )

17

40 }

41 if conf.Driver == "" || conf.Connection == "" {

42 conf.Driver = "sqlite3"

43 // Shared cache is required for multithreading

44 conf.Connection = fmt.Sprintf("file:%s?cache=shared&mode=rwc",

53 sq = squirrel.StatementBuilder.RunWith(squirrel.NewStmtCacheProxy(db))

54 switch conf.Driver {

55 case "sqlite3":

56 // To avoid locking "database locked" errors. Hard limitation of SQLite,

57 // when used from multiple threads.

58 db.SetMaxOpenConns(1)

59 case "postgres":

60 sq = sq.PlaceholderFormat(squirrel.Dollar)

main.go (https://github.com/c-bata/goptuna.git) Go · 104 lines

12 "syscall"

13

14 "gorm.io/driver/sqlite"

15 "gorm.io/gorm"

16

34

35 func main() {

36 db, err := gorm.Open(sqlite.Open("db.sqlite3"), &gorm.Config{})

37 if err != nil {

38 log.Fatal("failed to open database:", err)

41 log.Fatal("failed to get sql.DB:", err)

42 } else {

43 sqlDB.SetMaxOpenConns(1)

44 }

45 err = rdb.RunAutoMigrate(db)

store.go (https://github.com/canonical/go-dqlite.git) Go · 239 lines

15

16 "github.com/canonical/go-dqlite/internal/protocol"

17 _ "github.com/mattn/go-sqlite3" // Go SQLite bindings

18 )

19

46 //

47 // If the filename ends with ".yaml" then the YamlNodeStore implementation will

48 // be used. Otherwise the SQLite-based one will be picked, with default names

49 // for the schema, table and column parameters.

50 //

56

57 // Open the database.

58 db, err := sql.Open("sqlite3", filename)

59 if err != nil {

60 return nil, errors.Wrap(err, "failed to open database")