The async/await thing has been bothering me. I didn't do it because I had never used it and never really bothered/had the time to figure it out.
So, I figured now was as good a time as any - I'm supposed to be learning, right?
So for this instalment, dear reader, I went for the async thang.
Turns out it wasn't really all that difficult. I changed the connection/client - added an async keyword:
The bigger changes happened in the db functions, although they weren't really that big:
Other than this, I made some changes to the recipe interface:
I also changed the recipe db functions - mostly, I wasn't happy with the db and collection names.
I was working with a db called 'Recipes'. Which kind of forced me to use collections by recipe type - main, dessert, whatever.
I wasn't happy with this - what if I wanted to change the type of a recipe - who knows why, but I might want to. I would have to change the recipe type AND migrate it across collections.
This wasn't the one - I now settled for a 'Toasterfaves' db and a recipes collection. Maybe there will be other things to save with this site? As well as this, you might note I added the dbName argument to the db functions. This will open up those functions to be usable later on if/when we add more dbs.
That's pretty much it for now. I'm happier these things are done and I don't need to come back and refactor them further down the line.
I guess next, I will have to expose these functions - I assume using express. Then, I will have to get that api running on the cpanel server. That'll be fun...
- one thing worth noting - I can't be sure any of this is correct! But it works. And I'm pretty happy with it. If you have any suggestions, let me know.