tsk-6: Added docker support (#14)

Closes #6

Reviewed-on: phoenix/textsender-api#14
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-05 18:22:55 +00:00
committed by phoenix
parent d332cde84f
commit 2045465111
7 changed files with 200 additions and 6 deletions
+19 -1
View File
@@ -54,6 +54,25 @@ func NewDatabase(connString string) (*Database, error) {
return &Database{Pool: pool}, nil
}
func TableExists(ctx context.Context, conn *pgxpool.Pool, tableName string) (bool, error) {
var exists bool
query := `
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = $1
);
`
err := conn.QueryRow(ctx, query, tableName).Scan(&exists)
if err != nil {
return false, fmt.Errorf("error checking if table exists: %w", err)
}
return exists, nil
}
func (db *Database) Close() {
if db.Pool != nil {
db.Pool.Close()
@@ -115,4 +134,3 @@ func (db *Database) ResetDatabase(ctx context.Context) error {
return nil
}