add savequery API to save query details to database