Replace metadata query with sqlc
Remove old hand written SQL query