github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/dbal/dsn.go (about) 1 package dbal 2 3 import ( 4 "regexp" 5 ) 6 7 const ( 8 SQLiteInMemory = "sqlite://file::memory:?_fk=true" 9 SQLiteSharedInMemory = "sqlite://file::memory:?_fk=true&cache=shared" 10 ) 11 12 var dsnRegex = regexp.MustCompile(`^(sqlite://file:(?:.+)\?((\w+=\w+)(&\w+=\w+)*)?(&?mode=memory)(&\w+=\w+)*)$|(?:sqlite://(file:)?:memory:(?:\?\w+=\w+)?(?:&\w+=\w+)*)|^(?:(?::memory:)|(?:memory))$`) 13 14 // SQLite can be written in different styles depending on the use case 15 // - just in memory 16 // - shared connection 17 // - shared but unique in the same process 18 // see: https://sqlite.org/inmemorydb.html 19 func IsMemorySQLite(dsn string) bool { 20 return dsnRegex.MatchString(dsn) 21 }