aboutsummaryrefslogtreecommitdiffstats
path: root/internal/storage/sqlite3.go
blob: eff72af137e1d4a87f2da3fb0401d1bf88110c8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package storage

import (
	"fmt"
)

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
}