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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user