@@ -134,10 +134,27 @@ def create_sql_condition_for_visibility(
134134 return ''
135135
136136 @staticmethod
137- def create_sql_condition_for_active ( only_active : bool ,
138- container_name = 'c' ) -> str :
139- if only_active :
140- return 'AND NOT IS_DEFINED(%s.status) OR (IS_DEFINED(%s.status) AND %s.status = \' active\' )' % (container_name , container_name , container_name )
137+ def create_sql_active_condition (
138+ status_value : str , container_name = 'c'
139+ ) -> str :
140+ if status_value != None :
141+ not_defined_condition = ''
142+ condition_operand = ' AND '
143+ if status_value == 'active' :
144+ not_defined_condition = (
145+ 'AND NOT IS_DEFINED({container_name}.status)' .format (
146+ container_name = container_name
147+ )
148+ )
149+ condition_operand = ' OR '
150+
151+ defined_condition = '(IS_DEFINED({container_name}.status) AND {container_name}.status = \' {status_value}\' )' .format (
152+ container_name = container_name , status_value = status_value
153+ )
154+ return (
155+ not_defined_condition + condition_operand + defined_condition
156+ )
157+
141158 return ''
142159
143160 @staticmethod
@@ -232,7 +249,6 @@ def find(
232249 def find_all (
233250 self ,
234251 event_context : EventContext ,
235- only_active = True ,
236252 conditions : dict = None ,
237253 custom_sql_conditions : List [str ] = None ,
238254 custom_params : dict = None ,
@@ -254,14 +270,20 @@ def find_all(
254270 {"name" : "@offset" , "value" : offset },
255271 {"name" : "@max_count" , "value" : max_count },
256272 ]
273+
274+ status_value = None
275+ if conditions .get ('status' ) != None :
276+ status_value = conditions .get ('status' )
277+ conditions .pop ('status' )
278+
257279 params .extend (self .generate_params (conditions ))
258280 params .extend (custom_params )
259281 query_str = """
260282 SELECT * FROM c
261283 WHERE c.{partition_key_attribute}=@partition_key_value
262284 {conditions_clause}
263285 {visibility_condition}
264- {only_active_condition }
286+ {active_condition }
265287 {custom_sql_conditions_clause}
266288 {order_clause}
267289 OFFSET @offset LIMIT @max_count
@@ -270,7 +292,7 @@ def find_all(
270292 visibility_condition = self .create_sql_condition_for_visibility (
271293 visible_only
272294 ),
273- only_active_condition = self .create_sql_condition_for_active ( only_active ),
295+ active_condition = self .create_sql_active_condition ( status_value ),
274296 conditions_clause = self .create_sql_where_conditions (conditions ),
275297 custom_sql_conditions_clause = self .create_custom_sql_conditions (
276298 custom_sql_conditions
@@ -358,11 +380,11 @@ class CosmosDBDao(CRUDDao):
358380 def __init__ (self , repository : CosmosDBRepository ):
359381 self .repository = repository
360382
361- def get_all (self , only_active = True , conditions : dict = None , ** kwargs ) -> list :
383+ def get_all (self , conditions : dict = None , ** kwargs ) -> list :
362384 conditions = conditions if conditions else {}
363385 event_ctx = self .create_event_context ("read-many" )
364386 return self .repository .find_all (
365- event_ctx , only_active , conditions = conditions , ** kwargs
387+ event_ctx , conditions = conditions , ** kwargs
366388 )
367389
368390 def get (self , id ):
0 commit comments