feat: add Docker support, refactor DB layer, update API responses
This commit is contained in:
@@ -18,11 +18,11 @@ class DatabaseProvider {
|
||||
Future<void> initialize() async {
|
||||
final dotenv = DotEnv();
|
||||
|
||||
final host = dotenv['POSTGRES_HOST'] ?? 'localhost';
|
||||
final host = dotenv['POSTGRES_HOST'] ?? 'db';
|
||||
final port = int.parse(dotenv['POSTGRES_PORT'] ?? '5432');
|
||||
final databaseName = dotenv['POSTGRES_DB'] ?? 'family_safety';
|
||||
final username = dotenv['POSTGRES_USER'] ?? 'postgres';
|
||||
final password = dotenv['POSTGRES_PASSWORD'] ?? '';
|
||||
final password = dotenv['POSTGRES_PASSWORD'] ?? 'postgres';
|
||||
|
||||
try {
|
||||
final defaultConnection = await Connection.open(
|
||||
@@ -43,8 +43,7 @@ class DatabaseProvider {
|
||||
|
||||
if (results.isEmpty) {
|
||||
await defaultConnection.execute(
|
||||
Sql.named('CREATE DATABASE @dbName'),
|
||||
parameters: {'dbName': databaseName},
|
||||
Sql('CREATE DATABASE $databaseName'),
|
||||
);
|
||||
print('Database $databaseName created.');
|
||||
} else {
|
||||
@@ -78,7 +77,7 @@ class DatabaseProvider {
|
||||
await _dbConnection.execute(
|
||||
Sql.named('''
|
||||
CREATE TABLE IF NOT EXISTS geopositions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
x_value DOUBLE PRECISION NOT NULL,
|
||||
y_value DOUBLE PRECISION NOT NULL,
|
||||
last_update TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
@@ -265,7 +264,7 @@ class DatabaseProvider {
|
||||
Future<Geoposition?> getLatestPosition() async {
|
||||
final results = await _dbConnection.execute(
|
||||
Sql.named('''
|
||||
SELECT id, x_value, y_value, last_update, expires_at
|
||||
SELECT x_value, y_value, last_update, expires_at
|
||||
FROM geopositions
|
||||
WHERE expires_at > NOW()
|
||||
ORDER BY last_update DESC
|
||||
|
||||
Reference in New Issue
Block a user