diff --git a/geomagio/api/db/metadata_table.py b/geomagio/api/db/metadata_table.py index 9d32384b56b256a5c531c531f25afa11f94a9f02..4ac0454f9a2f1997a2050a832dad4f4f8f558bb7 100644 --- a/geomagio/api/db/metadata_table.py +++ b/geomagio/api/db/metadata_table.py @@ -108,17 +108,18 @@ async def get_metadata( metadata_valid: bool = None, ): query = metadata.select() - if id is not None: + if id: query = query.where(metadata.c.id == id) if category: query = query.where(metadata.c.category == category) - if network or station or channel or location: - query = ( - query.where(metadata.c.network.like(network or "%")) - .where(metadata.c.station.like(station or "%")) - .where(metadata.c.channel.like(channel or "%")) - .where(metadata.c.location.like(location or "%")) - ) + if network: + query = query.where(metadata.c.network == network) + if station: + query = query.where(metadata.c.station.like(station or "%")) + if channel: + query = query.where(metadata.c.channel.like(channel or "%")) + if location: + query = query.where(metadata.c.location.like(location or "%")) if starttime: query = query.where( or_(metadata.c.endtime == None, metadata.c.endtime > starttime) @@ -135,6 +136,8 @@ async def get_metadata( query = query.where(metadata.c.data_valid == data_valid) if metadata_valid is not None: query = query.where(metadata.c.metadata_valid == metadata_valid) + print(query) + print(network) rows = await database.fetch_all(query) return [Metadata(**row) for row in rows]