I believe that what you mean by class templates is the class definition. If so, avoid calling it class template. Anyway the answer in this case is that when a function is related to the class it belongs to the class as an instance method or as a static method, if not, it belongs in global scope as an ordinary function.
You should aim at grouping things together that have some logical connection, such as a db class dealing with connecting and querying the database in a general way, while you keep other classes that deal with a set of "related data" and in turn uses the db class to pass this data to and from the database.
The main idea is to keep such groups at low levels of responsibility. The db class doesn't deal with specific data, only the communication process with the database. Each "data class" doesn't deal with database communication, only with its own data and whatever subset of the db schema that relates to.