cotton
cotton copied to clipboard
Models question
Is there any possible way to create table based of a model, I think I can create a schema that follow the model, but that also means I have to maintain the both the schema create table AND the model types, which isn't the end of the world for maybe having a 1 - 3 models but once you get a decent number of models, I think it could be quite tedious to maintain both.
If it is possible to create a table from its model, that would be great to hear and also if any of this does not make sense, feel free to ask for more clarfication
Hi, thanks for asking. Currently, there's no way to generate a table from a model class. However, it's a nice feature to have. Honestly, I don't have enough experience in introspecting a database schema, but I will try my best to learn it and hopefully implement it in this library. If you or anyone else know how to do this, please let me know, I'm open for PR! 😃
I'm thinking of generating migration files from a model class, not creating the tables directly. Then, you can run the migration whenever you want to create the table. But if you have a better strategy to do this, I would love to know.
I think any strategy is better than none at all 😃, I have actually no experience on creating any ORM at all. However I've used alot in my time. Almost all of them have there own custom types. that you can plug into a model. I would presume that is for a good reason, as databases in generel tend to have more specific types than (what's provided in javascript) string, integer, etc. Hopefully that is some kind of hint / step in the right direction, with that being said. I'm totally clueless and only take what I just said with a grain of salt.
Thank you for replying so fast, I really do apperciate it & good luck, I'll be keeping a close eye out for any like-wise feature.
Here is an example project handling migrations specifically, if you need any inspiration for this.
https://deno.land/x/[email protected]
No problem, thank you very much @Yofou and @wyrd-code 😃
I think any strategy is better than none at all 😃, I have actually no experience on creating any ORM at all. However I've used alot in my time. Almost all of them have there own custom types. that you can plug into a model. I would presume that is for a good reason, as databases in generel tend to have more specific types than (what's provided in javascript) string, integer, etc. Hopefully that is some kind of hint / step in the right direction, with that being said. I'm totally clueless and only take what I just said with a grain of salt.
Thank you for replying so fast, I really do apperciate it & good luck, I'll be keeping a close eye out for any like-wise feature.
I have seen often in Node ORMs there is a "sync" feature, which is intended just to speed up development process and basically drops everything and recreate the tables based on the defined models/entities.
Also they support generating migrations based on entities/models changes.
I think both strategies are useful, but probably generating migrations based on models changes is higher priority one and "sync" is just a nice to have (and it can be dangerous, since you can delete all your data if you push it to production by accident).