Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #20

Closed
buttermiilk opened this issue Jul 29, 2020 · 4 comments
Closed

Question #20

buttermiilk opened this issue Jul 29, 2020 · 4 comments

Comments

@buttermiilk
Copy link

So um, are there anyway to change from PostgreSQL to something else? I feel like PostgreSQL isn't an option for me, and I would really appreciate it if there is a method for that.

Oh, if you can, may I ask for a list of stuff that I need to rewrite? Thanks.

@ravener
Copy link
Owner

ravener commented Jul 29, 2020

There isn't a direct way to change it but nothing stops you from changing the code. The main database driver is in structures/Settings.js then the connection logic is in structures/MiyakoClient.js other than that if the settings class is properly implemented the rest of the code should work as it does not directly touch the database. Let me know which database you are using. I've let my friend use the base framework of my bot except he wanted to use mongodb so I do have a mongodb implementation ready if you are interested

@buttermiilk
Copy link
Author

Ah, yes. May I take a look at it?

@ravener
Copy link
Owner

ravener commented Jul 29, 2020

Here you go: https://hastebin.com/foqelubaqu.js

Add that to structures/Settings.js

Then edit the client to connect a mongodb database and define it on client.db

Few major notes:

  • With postgresql we relied on the schema to include defaults, so we never do null checks etc and believe that the settings are always available. Since mongodb is dynamic we had to change the idea a little bit, the schema is defined in the code itself. The above class i sent you can see it will try to insert defaults which means we have to tell it the defaults whenever we construct them. So in the client the parts in this.settings that does new Settings(this, "guilds") will have to also describe defaults, e.g new Settings(this, "guilds", { prefix: "default prefix" }); do this for every keys you use to ensure default values.
  • In extensions/ members/users/guilds have a settings getter. It returns defaults if there is no db entry but with mongodb remove that line and use getDefaults(id) instead of the get(id) || { ... } defaults are already given in the db driver so lets use those.
  • I don't know if i missed anything else, test it out and lemme know if you have any questions.

@buttermiilk
Copy link
Author

I spent a few hours to get this work, and it did, but I think PostgreSQL does the job better than MongoDB a little bit. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants