You surely can do that but remember that work with files cost "too
much time"
I don't agree with Gepser. File content should be loaded once at server start and being stored in ram (object I mean) while runtime.
I would separate queries into some logical modules and then into tables or at least just tables:
json file:
{
"usersTable": {
"selectAll": "select * from user",
"selectSome": "select * from users where id > :id",
"insert": "insert into users values (:name, :second_name, )"
},
"messagesTable": {
"selectAll": ""
}
}
key-value file:
usersTable.selectAll=select * from user
userTable.selectSome=select * from users where id > :id
userTable.insert=insert into users values (:name, :second_name, )
messagesTable.selectAll=
- If the project is huge you dont want to store every single query in
one file. At least with key-value approach. Separate files by directories that contain module name.
- Use named parameters instead of positional. Otherwise it's ambiguous what parameter is when you don't see the query.
- Load file with sqls at application initialization. And use object at runtime.