How does eggjs implement any field model?

I recently played with the strapi framework and realized that the best thing about this structure is, one, any field model, and two, extensible plug-ins. Among them, the method of any field model is a little complicated. I haven"t figured it out for decades. I guess I haven"t known that much just when I"ve just come into contact with the back-end technology.

refer to any field model of strapi

even if several types are selected, these types will be saved to new tables in the database, such as creating article tables, and the fields of article will have corresponding types, so that the structure is good and flexible. There is no need to manually add codes such as mvc each time, and store the database directly.

for example, to create an article table, the article table has not yet added a field model, then select a string, date, and number in the background to make the title, author. And then build a structure similar to the MVC schema, which will naturally be saved to that article table.

this structure is worth my reference, but I don"t know how to implement this method.

what I am currently doing is using the eggjs framework, so how to implement this field model method in eggjs?

Last sentence: I hope you are my good teacher now! Thank you!

Mar.15,2021

Thank you for inviting me to say a few words. At present, the writing of the Model layer in Egg.js is chaotic, there is not a more unified scheme, and the respective ORM plug-ins also fight on their own, with many limitations, and there are big compatibility problems when multi-ORM coexist. For details, please refer to RFC-1775 redefine the Model layer . Personally, I currently use egg-sequelize , which I think is relatively easy to use, and sequelize is also relatively complete.


  1. A brief analysis of the meaning of the title, you should mean:
    1.1 through the [graphical interface] to add [attribute columns in the data table]. The effect is that [the corresponding data table (table_article) appears in MongoDB], and [corresponding data model (article.model)]
    1.2 is generated in the framework folder to correct your statement, it should be the framework of strapi [overall adopted MVC design example]. [1. 1] the structure of MVC is not generated, but Model
  2. is generated.
  3. how to achieve the effect mentioned in [1. 1]?
    2.1 although the impression is generated through the [graphical interface]. But it is always inseparable from the operation of the [command line]. In the strapi documentation there is a special introduction to [CLI] section, you can refer to and search the source code of the framework, always need to explore, others are just to help you explain the concept
    2.2 strapi is not the first to achieve [1.1] way of the framework, Laravel is also very typical. If you find strapi's English documents difficult to understand, you can take a look at Laravel's Chinese documents. As with strapi's [CLI], in Laravel we use the Artisan instruction
    2.3 strapi uses MongoDB, and you may also need to take a look at the command line instructions in the MongoDB documentation
  4. .

egg-sequelize documents are also recommended

Model

 

this is actually very simple. Requirements are similar to an article that can add any of 10 field and support multiple ones.
then you create an article table, and then create 10 field tables, each associated with an article table.

subsequent extensions are also easy, adding a field type only needs to add a new table.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e932d9-143a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e932d9-143a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?