move SQL query as function to libertree-db