1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from typing import List
16 # from o2ims.adapter import orm
17 from o2ims.domain.stx_object import StxGenericModel
18 from o2ims.domain.stx_repo import StxObjectRepository
19 from o2ims.domain.resource_type import ResourceTypeEnum
22 class StxObjectSqlAlchemyRepository(StxObjectRepository):
23 def __init__(self, session):
25 self.session = session
27 def _add(self, stx_obj: StxGenericModel):
28 self.session.add(stx_obj)
30 def _get(self, stx_obj_id) -> StxGenericModel:
31 return self.session.query(StxGenericModel).filter_by(
32 id=stx_obj_id).first()
34 def _list(self, type: ResourceTypeEnum) -> List[StxGenericModel]:
35 return self.session.query(StxGenericModel).filter_by(
36 type=type).order_by(StxGenericModel.updatetime.desc()).all()
38 def _update(self, stx_obj: StxGenericModel):
39 self.session.add(stx_obj)