/databases/*
This file describes the router for:
where, id
may be left out.
Database resources represent the available databases that may be used for the gateways.
One can register a new database (by using POST /databases
) or look through the
available databases (by using GET /databases
) using standard OPTIMADE filtering.
get_database(request, database_id, params)
async
GET /databases/{database ID}
Return a single
LinksResource
representing the database resource object with id={database ID}
.
Source code in optimade_gateway/routers/databases.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | @ROUTER.get(
"/databases/{database_id:path}",
response_model=DatabasesResponseSingle,
response_model_exclude_defaults=False,
response_model_exclude_none=False,
response_model_exclude_unset=True,
tags=["Databases"],
responses=ERROR_RESPONSES,
)
async def get_database(
request: Request,
database_id: str,
params: Annotated[SingleEntryQueryParams, Depends()],
) -> DatabasesResponseSingle:
"""`GET /databases/{database ID}`
Return a single
[`LinksResource`](https://www.optimade.org/optimade-python-tools/api_reference/models/links/#optimade.models.links.LinksResource)
representing the database resource object with `id={database ID}`.
"""
collection = await collection_factory(CONFIG.databases_collection)
params.filter = f'id="{database_id}"'
(
result,
data_returned,
more_data_available,
fields,
include_fields,
) = await collection.afind(params=params)
if fields or include_fields and result is not None:
result = handle_response_fields(result, fields, include_fields)
result = result[0] if isinstance(result, list) and data_returned else None
return DatabasesResponseSingle(
links=ToplevelLinks(next=None),
data=result,
meta=meta_values(
url=request.url,
data_returned=data_returned,
data_available=await collection.acount(),
more_data_available=more_data_available,
schema=CONFIG.schema_url,
),
)
|
get_databases(request, params)
async
GET /databases
Return overview of all (active) databases.
Source code in optimade_gateway/routers/databases.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | @ROUTER.get(
"/databases",
response_model=DatabasesResponse,
response_model_exclude_defaults=False,
response_model_exclude_none=False,
response_model_exclude_unset=True,
tags=["Databases"],
responses=ERROR_RESPONSES,
)
async def get_databases(
request: Request,
params: Annotated[EntryListingQueryParams, Depends()],
) -> DatabasesResponse:
"""`GET /databases`
Return overview of all (active) databases.
"""
return await get_entries(
collection=await collection_factory(CONFIG.databases_collection),
response_cls=DatabasesResponse,
request=request,
params=params,
)
|
post_databases(request, database)
async
POST /databases
Create/Register or return an existing
LinksResource
,
representing a database resource object, according to database
.
Source code in optimade_gateway/routers/databases.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 | @ROUTER.post(
"/databases",
response_model=DatabasesResponseSingle,
response_model_exclude_defaults=False,
response_model_exclude_none=False,
response_model_exclude_unset=True,
tags=["Databases"],
responses=ERROR_RESPONSES,
)
async def post_databases(
request: Request, database: DatabaseCreate
) -> DatabasesResponseSingle:
"""`POST /databases`
Create/Register or return an existing
[`LinksResource`](https://www.optimade.org/optimade-python-tools/api_reference/models/links/#optimade.models.links.LinksResource),
representing a database resource object, according to `database`.
"""
result, created = await resource_factory(database)
collection = await collection_factory(CONFIG.databases_collection)
return DatabasesResponseSingle(
links=ToplevelLinks(next=None),
data=result,
meta=meta_values(
url=request.url,
data_returned=1,
data_available=await collection.acount(),
more_data_available=False,
schema=CONFIG.schema_url,
**{f"_{CONFIG.provider.prefix}_created": created},
),
)
|