diff options
Diffstat (limited to 'internal/storage/sqlite3.go')
| -rw-r--r-- | internal/storage/sqlite3.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/storage/sqlite3.go b/internal/storage/sqlite3.go new file mode 100644 index 0000000..877dc7e --- /dev/null +++ b/internal/storage/sqlite3.go @@ -0,0 +1,48 @@ +package storage + +import ( + "fmt" + + "github.com/eugenetriguba/bolt/internal/configloader" +) + +type SqliteAdapter struct{} + +func (s SqliteAdapter) ConvertGenericPlaceholders( + query string, + argsCount int, +) string { + // The sqlite driver uses ? as a generic placeholder, + // so no translation is necessary. + return query +} + +func (s SqliteAdapter) TableExists( + executor sqlExecutor, + tableName string, +) (bool, error) { + var count int + err := executor.QueryRow(` + SELECT COUNT(*) + FROM sqlite_master + WHERE type='table' AND name=?; + `, tableName).Scan(&count) + if err != nil { + return false, fmt.Errorf( + "unable to check if %s exists: %w", + tableName, + err, + ) + } + + return count > 0, nil +} + +func (s SqliteAdapter) DatabaseName(executor sqlExecutor) (string, error) { + return "main", nil +} + +func (s SqliteAdapter) CreateDSN(cfg configloader.ConnectionConfig) string { + // Note: Use the dbname as the sqlite db name/path + return cfg.DBName +} |