1
1
"""titiler.openeo.services duckDB."""
2
2
3
+ import json
3
4
import uuid
4
5
from typing import Any , Dict , List , Optional
5
6
9
10
from .base import ServicesStore
10
11
11
12
12
- @define (kw_only = True , init = False )
13
+ @define (kw_only = True )
13
14
class DuckDBStore (ServicesStore ):
14
15
"""DuckDB Service Store."""
15
16
@@ -45,23 +46,23 @@ def get_service(self, service_id: str) -> Optional[Dict]:
45
46
46
47
return {
47
48
"id" : result [0 ],
48
- ** result [1 ],
49
+ ** json . loads ( result [1 ]) ,
49
50
}
50
51
51
52
def get_services (self , ** kwargs ) -> List [Dict ]:
52
53
"""Return All Services."""
53
54
with duckdb .connect (self .store ) as con :
54
55
results = con .execute (
55
56
"""
56
- SELECT service_id, service
57
+ SELECT service_id, json( service)
57
58
FROM services
58
59
"""
59
60
).fetchall ()
60
61
61
62
return [
62
63
{
63
64
"id" : result [0 ],
64
- ** result [1 ],
65
+ ** json . loads ( result [1 ]) ,
65
66
}
66
67
for result in results
67
68
]
@@ -71,20 +72,17 @@ def get_user_services(self, user_id: str, **kwargs) -> List[Dict]:
71
72
with duckdb .connect (self .store ) as con :
72
73
results = con .execute (
73
74
"""
74
- SELECT service_id, service
75
+ SELECT service_id, service::JSON
75
76
FROM services
76
77
WHERE user_id = ?
77
78
""" ,
78
79
[user_id ],
79
80
).fetchall ()
80
81
81
- if not results :
82
- raise ValueError (f"Could not find service for user: { user_id } " )
83
-
84
82
return [
85
83
{
86
84
"id" : result [0 ],
87
- ** result [1 ],
85
+ ** json . loads ( result [1 ]) ,
88
86
}
89
87
for result in results
90
88
]
0 commit comments