(dbPath string)
| 17 | } |
| 18 | |
| 19 | func NewDatabase(dbPath string) (*DBMS, error) { |
| 20 | var err error |
| 21 | |
| 22 | dbms := &DBMS{ |
| 23 | exists: true, |
| 24 | } |
| 25 | |
| 26 | // Enable WAL mode and other performance optimizations via connection string |
| 27 | connStr := dbPath + "?_journal_mode=WAL&_synchronous=NORMAL&_busy_timeout=10000&_cache_size=-64000" |
| 28 | dbms.database, err = sql.Open("sqlite3", connStr) |
| 29 | if err != nil { |
| 30 | dbms.exists = false |
| 31 | } |
| 32 | |
| 33 | if dbms.exists { |
| 34 | dbms.database.SetMaxOpenConns(1) |
| 35 | dbms.database.SetMaxIdleConns(1) |
| 36 | |
| 37 | err = dbms.DatabaseInit() |
| 38 | if err != nil { |
| 39 | dbms.exists = false |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if dbms.exists { |
| 44 | dbms.prepareStatements() |
| 45 | } |
| 46 | |
| 47 | return dbms, err |
| 48 | } |
| 49 | |
| 50 | func (dbms *DBMS) prepareStatements() { |
| 51 | var err error |
nothing calls this directly
no test coverage detected