While you technically can have server functions in your route files, it’s not always the best choice.
For code that you never ever want in your client, it’s a best practice to move them into separate files, and name with the .server
convention. For example: posts.server.ts
Note that you can absolutely interact with the database directly in your loader within your route module. I just find that it's typically better from a code organization standpoint to put all database interactions in a separate module.