tsk-8: Added docker support (#13)
Closes #8 Reviewed-on: phoenix/textsender-auth#13 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -27,11 +27,9 @@ type ConnectionInfo struct {
|
||||
SslMode string
|
||||
}
|
||||
|
||||
|
||||
const Port = "9080"
|
||||
const App_Name = "textsender_auth"
|
||||
|
||||
|
||||
func (ci ConnectionInfo) Parse() string {
|
||||
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", ci.Username, ci.Password, ci.Host, ci.Port, ci.Database, ci.SslMode)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user