Issue in select-bot example using sequelize findOne()

For this example https://gomix.com/#!/project/slack-bot
This had be chasing my tail for many hours…

In datastore.js function get() it does the following.
Token.findOne({"key":key})

I believe the corrected call for get() should be I believe.
Token.findOne({ where: { "key":key } })

As an extra note datastore.js can be made a lot simpler as sequelize is already based on promises.

1 Like

Hi Robin,

Thanks for the report, and sorry for the trouble sorting out the issue in your remix!

I’ve updated the get call as your correction works well for me. Datastore.js can certainly be made simpler, and I think that’s a holdover from when we had support for DynamoDB, and wrapped that in promises.

If you’d like to share your remix as an improved version, we’d be happy to feature your contribution!

I created a remix with the refactored datastore.js. I went to verify they work in this new project but encountered a problem.

Due to the switch to sequelize with sqlite in memory model, ever time server side starts it has no bot token. Even if i then use the Add to Slack feature to set a bot token the server side process is already running and won’t pick up the new value in the database. Then every restart on server side loses that set bot token, with these constraints the bot can never send a message I believe as the server side never has a loaded valid bot token value.

I tried switch over to a persistent db by setting storage:'.data/database.sqlite' in the setup of sequelize, but this fails with errors as if the .data folder does not exist or is not writable.

This was not a surprise as previously when I created the other project remix of slack bot i couldn’t get sequelize to use path storage. I ended up creating a remix of https://gomix.com/#!/project/sqlite3-db and then copying all the bot stuff back into the project.

For me at least it seems remix of the slack-bot then adding storage is not possible.

Anyway https://gomix.com/#!/project/slack-bot-fixes is just a refactor to improve datastore.js but I can’t fully test it due to the in memory db model, The datastore library does appear to work as it connects gets and sets values to the database.

LOL. got warning about only 2 links per post as new user… i had the slack-bot-fixes link in twice so no big deal.

It sounds like the path isn’t being created when you’re calling from a new project. If you create the folder yourself in the editor, then you should be able to write to it. For example, create a file called ‘.data/temp.txt’ and it should then your code should then create your sqlite file in that folder and work. You can then just remove that temporary text file. This is a known issue we’ll be addressing.

Ah, that makes sense, didn’t think to try that.
Cheers.