From d34db5ee93ce7b68f0ab47ef9190847233dfab43 Mon Sep 17 00:00:00 2001
From: Travis Rivers <trivers@contractor.usgs.gov>
Date: Mon, 9 Nov 2020 17:08:52 -0700
Subject: [PATCH] separate sncl query parameters

---
 geomagio/api/db/metadata_table.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/geomagio/api/db/metadata_table.py b/geomagio/api/db/metadata_table.py
index 9d32384b..4ac0454f 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]
 
-- 
GitLab