Object-relational mapping code generation method and apparatus, and computer storage medium

By automatically generating object-relational mapping code, the problem of a large amount of manual work in database development is solved, enabling efficient database structure definition and operation, and improving development efficiency and software stability.

CN116226165BActive Publication Date: 2026-03-17BEIJING HONGTENG INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-07
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

During database development, developers need to manually map the database data structure into structures in object-oriented programming languages, resulting in a huge workload and low efficiency.

Method used

By obtaining the database address and determining the database information, and using preset mapping templates and operation templates to map the data table into a structure, object-relational mapping code is automatically generated, realizing automatic mapping and operation between the structure and the database.

Benefits of technology

It improves the efficiency of database structure definition, avoids the tedious task of manual definition, ensures that the structure corresponds to the database structure, and the generated object-relational mapping code is compatible with the operation syntax of various mainstream databases, thereby improving software stability and development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116226165B_ABST
    Figure CN116226165B_ABST
Patent Text Reader

Abstract

The application discloses an object relationship mapping code generation method and device and a computer storage medium. The method comprises the following steps: obtaining a database address; determining database information according to the database address; mapping a data table of a database into a structure according to a preset mapping template and the database information; and generating an object relationship mapping code for the structure according to a preset operation template, wherein the object relationship mapping code is used for operating the structure to operate the database. According to the embodiment of the application, the database object is strictly mapped into the corresponding structure, the tediousness of manually defining the structure is avoided, the database structure definition efficiency is improved, and various problems that the structure does not correspond to the database structure are avoided. Meanwhile, a unified object relationship mapping code is generated for each object, the object relationship mapping codes are compatible with the operation syntax of various databases, the behaviors of all objects are consistent, and the software stability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data, and in particular to a method, apparatus and computer storage medium for generating object-relational mapping code. Background Technology

[0002] In database development, directly manipulating data in database tables using SQL commands is very inconvenient. Often, it's necessary to map the database data structure to structs or classes in object-oriented programming languages. This way, adding, deleting, modifying, and querying struct or class objects is equivalent to manipulating data in the database.

[0003] However, database tables contain a large amount of data, and mapping each database data structure to the structures in an object-oriented programming language would waste a significant amount of developers' time. Furthermore, manipulating the database requires operating on each structure or class object individually, which is inconvenient and results in a huge workload for developers, leading to low development efficiency. Summary of the Invention

[0004] This application provides a method, apparatus, and computer storage medium for generating object-relational mapping code, which can solve the problem of the huge workload and low development efficiency that developers need to complete manually in the existing database development process.

[0005] In a first aspect, embodiments of this application provide a method for generating object-relational mapping code, including:

[0006] Obtain the database address; determine the database information based on the database address; map the database tables into structures according to a preset mapping template and the database information; generate object-relational mapping code for the structures according to a preset operation template, the object-relational mapping code being used to operate the structures to perform operations on the database.

[0007] In one possible implementation, mapping the database tables to structures based on a preset mapping template and the database information specifically includes: parsing the database information to obtain the table structure, table field types, and table fields; and mapping the table fields to structure fields based on the mapping template, the table structure, and the table field types to generate a structure.

[0008] In one possible implementation, the step of mapping the data table fields to structure fields and generating a structure based on the mapping template, the data table structure, and the data table field types specifically includes: converting the data table structure into a structure frame based on the mapping template; and converting the data table fields into structure fields based on the mapping template and the data table field types to generate a structure.

[0009] In one possible implementation, the step of converting the data table fields into structure fields and generating a structure based on the mapping template and the data table field types specifically includes: converting the data table fields into MySQL defined fields based on the data table field types; and mapping the MySQL defined fields into structure fields based on the mapping template to generate a structure.

[0010] In one possible implementation, generating object-relational mapping code for the structure according to a preset operation template specifically includes: generating a MySQL instance for the structure according to the preset operation template; and generating corresponding object-relational mapping code based on the MySQL instance.

[0011] In one possible implementation, after generating operation methods for each structure according to the operation template, the object-relational mapping code generation method further includes: classifying the object-relational mapping code to generate an operation method set; packaging the operation method set to generate a mapping data package; and using the mapping data package to transmit the operation methods.

[0012] In one possible implementation, after classifying the object-relational mapping code and generating an operation method set, the object-relational mapping code generation method further includes: at each predetermined classification time, determining whether there is discrete object-relational mapping code that does not belong to the object-relational mapping code of the operation method set; if there is discrete object-relational mapping code, classifying the discrete object-relational mapping code as part of the operation method set.

[0013] In one possible implementation, the step of packaging the operation method set to generate a mapping data packet specifically includes: determining whether a predetermined packaging condition is met at each predetermined packaging time; if the predetermined packaging condition is met, packaging the operation method set to generate a mapping data packet.

[0014] Secondly, embodiments of this application provide an object-relational mapping (ORM) code generation apparatus, comprising: an acquisition module for acquiring a database address; a determination module for determining database information based on the database address; a mapping module for mapping database tables into structures according to a preset mapping template; and a generation module for generating ORM code for each structure according to a preset operation template, wherein the ORM code is used to operate the structure to perform operations on the database.

[0015] In one possible implementation, the mapping module specifically includes: a parsing submodule, used to parse the database information to obtain the data table structure, data table field types, and data table fields; and a mapping submodule, used to map the data table fields into structure fields according to the mapping template, the data table structure, and the data table field types, thereby generating a structure.

[0016] In one possible implementation, the mapping submodule specifically includes: a frame unit, used to convert the data table structure into a structure frame according to the mapping template; and a field unit, used to convert the data table fields into structure fields according to the mapping template and the data table field types, thereby generating a structure.

[0017] In one possible implementation, the field unit specifically includes: a conversion subunit, used to convert the data table field into a MySQL defined field according to the data table field type; and a mapping subunit, used to map the MySQL defined field into a structure field according to the mapping template, thereby generating a structure.

[0018] In one possible implementation, the generation module specifically includes: an instance submodule, used to generate a MySQL instance for the structure according to the preset operation template; and a code submodule, used to generate corresponding object-relational mapping code based on the MySQL instance.

[0019] In one possible implementation, the object-relational mapping code generation device further includes: a classification module for classifying the object-relational mapping code and generating an operation method set; and a packaging module for packaging the operation method set and generating a mapping data packet; the mapping data packet is used to transmit the operation methods.

[0020] In one possible implementation, the object relation mapping code generation device further includes: a timing module, used to determine whether there is discrete object relation mapping code at a predetermined classification time, wherein the discrete object relation mapping code is an object relation mapping code that does not belong to the operation method set; and an adding module, used to add the discrete object relation mapping code to the operation method set if there is discrete object relation mapping code.

[0021] In one possible implementation, the packaging module specifically includes: a detection submodule, used to determine whether the predetermined packaging conditions are met at each predetermined packaging time; and a packaging submodule, used to package the operation method set and generate a mapping data packet if the predetermined packaging conditions are met.

[0022] Thirdly, embodiments of this application provide an object-relational mapping (ORM) code generation apparatus, comprising: a processor and a memory; wherein the memory stores a computer program adapted to be loaded and executed by the processor to: obtain a database address; determine database information based on the database address; map data tables of the database into structures based on a preset mapping template and the database information; and generate ORM code for the structures based on a preset operation template, wherein the ORM code is used to operate the structures to operate the database.

[0023] In one possible implementation, when the processor maps a database table into a structure based on a preset mapping template and the database information, it specifically performs the following steps: parsing the database information to obtain the table structure, table field types, and table fields; and mapping the table fields into structure fields based on the mapping template, the table structure, and the table field types to generate a structure.

[0024] In one possible implementation, the processor maps the data table fields to structure fields based on the mapping template, the data table structure, and the data table field types. When generating the structure, the processor specifically performs the following steps: converting the data table structure into a structure frame based on the mapping template; and converting the data table fields into structure fields based on the mapping template and the data table field types to generate the structure.

[0025] In one possible implementation, the processor converts the data table fields into structure fields based on the mapping template and the data table field types. When generating the structure, the processor specifically performs the following steps: converting the data table fields into MySQL defined fields based on the data table field types; mapping the MySQL defined fields into structure fields based on the mapping template, and generating the structure.

[0026] In one possible implementation, when the processor generates object-relational mapping code for the structure according to a preset operation template, it specifically performs the following: generating a MySQL instance for the structure according to the preset operation template; and generating corresponding object-relational mapping code based on the MySQL instance.

[0027] In one possible implementation, before the processor generates operation methods for each structure according to the operation template, it is further configured to: classify the object relational mapping code to generate an operation method set; package the operation method set to generate a mapping data packet; and use the mapping data packet to transmit the operation methods.

[0028] In one possible implementation, after classifying the object-relational mapping code and generating an operation method set, the object-relational mapping code generation method further includes: at each predetermined classification time, determining whether there is discrete object-relational mapping code, which is object-relational mapping code that does not belong to the operation method set; if there is discrete object-relational mapping code, then adding the discrete object-relational mapping code to the operation method set.

[0029] In one possible implementation, the step of packaging the operation method set to generate a mapping data packet specifically includes: determining whether a predetermined packaging condition is met at each predetermined packaging time; if the predetermined packaging condition is met, packaging the operation method set to generate a mapping data packet.

[0030] Fourthly, embodiments of this application provide a computer storage medium storing a plurality of instructions, which are adapted to be loaded by a processor and executed by the method steps provided in the first aspect or any implementation thereof of the embodiments of this application.

[0031] Fifthly, embodiments of this application provide a computer program product containing instructions that, when run on a computer or processor, cause the computer or processor to execute the encoding method provided by the first aspect of the embodiments of this application or any possible implementation thereof.

[0032] The embodiments of this application strictly map database objects to corresponding structures, avoiding the tedious task of manually defining structures, improving the efficiency of database structure definition, and avoiding various problems caused by incompatibility between structures and database structures. Simultaneously, a unified set of object-relational mapping (ORM) code is generated for each object. This ORM code is compatible with the operation syntax of various mainstream databases, ensuring consistent behavior across all objects and improving software stability. Since both structure and ORM code are automatically generated, the problem of the huge workload and low development efficiency that developers need to complete manually in existing database development processes is solved.

[0033] Understandably, the object-relational mapping code generation apparatus provided in the second aspect, the object-relational mapping code generation apparatus provided in the third aspect, the computer storage medium provided in the fourth aspect, and the computer program product provided in the fifth aspect are all used to execute the object-relational mapping code generation method provided in the first aspect. Therefore, the beneficial effects they can achieve can be referred to in the beneficial effects of the object-relational mapping code generation method provided in the first aspect, and will not be repeated here. Attached Figure Description

[0034] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0035] Figure 1 A schematic diagram of an exemplary system architecture to which the technical solutions of the embodiments of this application can be applied is shown.

[0036] Figure 2 This is a flowchart illustrating an object-relational mapping code generation method provided in an embodiment of this application.

[0037] Figure 3 It shows according to Figure 2 A flowchart illustrating a specific implementation of step S300 in the object relation mapping code generation method shown in the corresponding embodiment.

[0038] Figure 4 It shows according to Figure 3 A flowchart illustrating a specific implementation of step S320 in the object relation mapping code generation method shown in the corresponding embodiment.

[0039] Figure 5 It shows according to Figure 2 A flowchart illustrating another object-relational mapping code generation method in a corresponding embodiment.

[0040] Figure 6 It shows Figure 2 A flowchart illustrating another object-relational mapping code generation method according to a corresponding embodiment.

[0041] Figure 7 This is a schematic diagram of the structure of an object relation mapping code generation device provided in an embodiment of this application.

[0042] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0043] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.

[0044] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.

[0045] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0046] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0047] Figure 1 A schematic diagram of an exemplary system architecture to which the technical solutions of the embodiments of this application can be applied is shown.

[0048] like Figure 1 As shown, the system architecture may include terminal devices (such as...) Figure 1 The device shown includes one or more of a smartphone 101, tablet 102, and portable computer 103 (which could also be a desktop computer, etc.), a network 104, and a server 105. The network 104 serves as a medium for providing a communication link between the terminal device and the server 105. The network 104 can include various connection types, such as wired communication links, wireless communication links, etc.

[0049] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, there can be any number of terminal devices, networks, and servers. For example, server 105 could be a server cluster composed of multiple servers.

[0050] Users can interact with server 105 via network 104 using terminal devices to receive or send messages, etc. Server 105 can be a server that provides various services. For example, a user can upload a database address to server 105 using terminal device 103 (or terminal device 101 or 102). Server 105 can determine the database information based on the database address; map the database tables into structures according to a preset mapping template and the database information; and generate object-relational mapping code for the structures according to a preset operation template. The object-relational mapping code is used to operate the structures to operate the database.

[0051] It should be noted that the object-relational mapping (ORM) code generation method provided in this application embodiment is generally executed by server 105, and correspondingly, the ORM code generation device is generally located in server 105. However, in other embodiments of this application, the terminal device may also have similar functions to the server, thereby executing the ORM code generation scheme provided in this application embodiment.

[0052] The implementation details of the technical solutions in the embodiments of this application are described in detail below:

[0053] Figure 2 A flowchart of an object-relational mapping (ORM) code generation method according to an embodiment of this application is shown. This ORM code generation method can be executed by a server, which may be... Figure 1 The server shown. (Refer to...) Figure 2 As shown, this object-relational mapping code generation method includes at least the following:

[0054] Step S100: Obtain the database address.

[0055] Step S200: Determine the database information based on the database address.

[0056] Step S300: Map the database tables into structures according to the preset mapping template and the database information.

[0057] Step S400: Generate object-relational mapping code for the structure according to a preset operation template. The object-relational mapping code is used to operate the structure to operate the database.

[0058] In this embodiment, the database address is first obtained, then the corresponding database information is determined, then the database tables are mapped into structures according to the preset mapping template and the database information, and finally, object-relational mapping code is generated for the structures according to the preset operation template.

[0059] The embodiments of this application strictly map database objects to corresponding structures, avoiding the tedious task of manually defining structures, improving the efficiency of database structure definition, and avoiding various problems caused by incompatibility between structures and database structures. Simultaneously, a unified set of object-relational mapping (ORM) code is generated for each object. This ORM code is compatible with the operation syntax of various mainstream databases, ensuring consistent behavior across all objects and improving software stability. Since both structure and ORM code are automatically generated, the problem of the huge workload and low development efficiency that developers need to complete manually in existing database development processes is solved.

[0060] In step S100, the address of the database is obtained, and various data in the database can be retrieved by using the database address as an index.

[0061] In step S200, the database address can be used as an index to retrieve various data from the database, including database information. Database information is information related to database operation, such as database table information, parsed table structure, and database field information.

[0062] In step S300, after determining the database information, the corresponding structure can be created according to the preset mapping template. The specific method for creating the structure can be referred to in the following embodiment.

[0063] Specifically, the above-mentioned struct can be a Golang struct, and the above-mentioned mapping template can be a mapping template of type map.

[0064] In some embodiments, this map-type mapping template maps fields of type int, tinyint, smallint, mediumint, etc., in a data table to Golang int type fields; and maps bigint type fields to int64 type fields. This map-type mapping template covers almost all field types, including complex field types such as time, blob, and binary. This allows database entities to be transformed into Golang structs.

[0065] Specifically, in some embodiments, the specific implementation of step S300 can be found in [reference needed]. Figure 3 . Figure 3 It is based on Figure 2 The detailed description of step S300 in the object-relational mapping code generation method shown in the corresponding embodiment is as follows: In the object-relational mapping code generation method, the database information includes database table information and parsed table structure. Step S300 may include the following steps:

[0066] Step S310: Parse the database information to obtain the data table structure, data table field types, and data table fields.

[0067] Step S320: Based on the mapping template, the data table structure, and the data table field types, map the data table fields to structure fields to generate a structure.

[0068] In this embodiment, the database information is first parsed to obtain information related to the database tables, such as the structure, fields, and field types. Then, based on the above information related to the database tables, mapping is performed according to the mapping template to obtain the corresponding structure.

[0069] In step S310, the database information is parsed, that is, the database information is analyzed and decomposed to determine the table structure, field types and fields of the data tables in the database, which can be achieved through SQL commands.

[0070] In step S320, the corresponding structure can be determined based on the data table structure and in conjunction with the mapping template. Similarly, the corresponding structure fields can be determined based on the data table fields and in conjunction with the mapping template.

[0071] Specifically, in some embodiments, the specific implementation of step S320 can be found in [reference needed]. Figure 4 . Figure 4 It is based on Figure 3 A detailed description of step S320 in the object-relational mapping code generation method shown in the corresponding embodiment: Step S320 in the object-relational mapping code generation method may include the following steps:

[0072] Step S321: Based on the mapping template, the data table structure is transformed into a structure frame.

[0073] Step S322: Based on the mapping template and the data table field type, the data table fields are converted into structure fields to generate a structure.

[0074] In this embodiment, the corresponding structure is first determined based on the data table structure and combined with the mapping template, and the structure framework is built. Then, the data table fields are converted into structure segment fonts and filled into the built framework to generate the structure.

[0075] In step S321, the corresponding structure can be determined based on the data table structure and in conjunction with the mapping template.

[0076] In step S322, for fields of different types in the data table, they are converted according to the corresponding field type. For example, fields of type int, tinyint, smallint, mediumint, etc. in the data table are mapped to Golang int type fields; fields of type bigint are mapped to int64 type fields, etc.

[0077] Specifically, in some embodiments, the specific implementation of step S322 can be found in the following embodiments. This embodiment is based on... Figure 4 According to the detailed description of step S322 in the object-relational mapping code generation method shown in the corresponding embodiment, step S322 in the object-relational mapping code generation method may include the following steps:

[0078] Based on the data table field type, convert the data table fields into MySQL defined fields;

[0079] Based on the mapping template, the MySQL defined fields are mapped to structure fields to generate a structure.

[0080] In this embodiment, the data table fields are first converted into MySQL defined fields based on their field types. Then, the MySQL defined fields are mapped into structure fields using a mapping template, completing the conversion from data table fields to structure fields. This method of first converting to MySQL defined fields and then to structure fields is compatible with more databases, especially domestic databases such as DM Database, Kingbase Database, Oceanbase Database, ShenTong Database, and Nantong Database. It solves the problem of incomplete adaptation and support for domestic databases during the current object-relational mapping development process, which requires engineers to adapt each database individually, resulting in a large amount of repetitive work. Furthermore, because this embodiment is compatible with more databases, it also solves the problem of low development efficiency caused by poor compatibility with domestic databases.

[0081] After converting all data table fields into structure fields, we obtain the structure corresponding to the data table. When we need to operate on the data table, we can indirectly operate on the data table by manipulating the structure.

[0082] In step S400, after obtaining the structure, object-relational mapping (ORM) code can be generated for the structure according to a preset operation template. Engineers can use this ORM code to manipulate any structure and indirectly operate on the corresponding database.

[0083] The object-relational mapping code mentioned above is the code that implements the operation methods. Different object-relational mapping codes can implement operation methods such as adding records, deleting records based on conditions, querying the total count, batch adding, batch modifying, saving records (updating if they exist, adding if they don't), retrieving a single record by ID, querying a single record by a specified field, retrieving all table data in a table, and retrieving table records by pagination.

[0084] Specifically, in some embodiments, the specific implementation of step S400 can be found in the following embodiments. This embodiment is based on... Figure 2 The detailed description of step S400 in the object-relational mapping code generation method shown in the corresponding embodiment includes the following steps:

[0085] A MySQL instance is generated for the structure according to the preset operation template.

[0086] Generate the corresponding object-relational mapping code based on the MySQL instance.

[0087] In this embodiment, a MySQL instance is first generated for the structure based on a preset operation template and the MySQL definition corresponding to the data table. Then, object-relational mapping code compatible with domestic databases is generated based on the MySQL instance to improve compatibility with domestic databases.

[0088] In this context, a MySQL instance appears on the system as a service process with an architecture similar to SQL Server and the Windows version of Oracle. It consists of threads and memory, used to manipulate database files. Typically, a single MySQL instance can operate on one or more databases; in a clustered environment, multiple MySQL instances can also operate on one or more databases.

[0089] In some embodiments of this application, such as Figure 5 As shown, after step S400, the object-relational mapping code generation method further includes:

[0090] Step S500: Classify the object relation mapping code and generate an operation method set.

[0091] Step S600: Package the operation method set to generate a mapping data package.

[0092] In some embodiments of this application, after generating object-relational mapping (ORM) code, the ORM code can be categorized to form a collection of ORM code, i.e., a set of operation methods. This set of operation methods is then packaged to generate a mapping data package. The mapping data package can be loaded into any project. When operation methods are needed, the corresponding ORM code can be directly called from the set of operation methods to perform database operations.

[0093] In some embodiments of this application, such as Figure 6 As shown, after step S500, the object-relational mapping code generation method further includes:

[0094] Step S501: At each predetermined classification time, determine whether there is a discrete object relation mapping code, wherein the discrete object relation mapping code is an object relation mapping code that does not belong to the operation method set.

[0095] Step S502: If there is discrete object relation mapping code, then add the discrete object relation mapping code to the operation method set.

[0096] In this embodiment, the operation method set can be updated. At each predetermined classification time, it is determined whether there are object relation mapping codes (i.e. discrete object relation mapping codes) that have not yet been added to the operation method set. If discrete object relation mapping codes exist, they can be directly added to the operation method set.

[0097] In step S501, the predetermined classification time can be the time when a new structure is generated, the time when a new operation method is generated, or the time when a fixed time interval is reached, such as every minute.

[0098] Whether a discrete object relational mapping code is generated can be determined indirectly by checking if a new structure or new object relational mapping code is generated, or it can be determined directly by comparison.

[0099] In step S502, the update of the operation method set is completed after the discrete object relation mapping code is added to the operation method set.

[0100] In step S600, there are multiple ways to package the operation method set, and the following embodiments can be referred to for details.

[0101] Specifically, in some embodiments, the specific implementation of step S600 can be found in the following embodiments. This embodiment is based on... Figure 4 The detailed description of step S600 in the object-relational mapping code generation method shown in the corresponding embodiment includes the following steps:

[0102] At each scheduled packaging time, confirm whether the packaging conditions are met.

[0103] If the predetermined packaging conditions are met, the set of operation methods is packaged to generate a mapping data packet.

[0104] In this embodiment, the mapping data package can also be updated. The mapping data package can be loaded into various projects. Updating the mapping data package enables each project to use the new object-relational mapping code in real time, improving its scalability, broadening its application scenarios, and making it more universally applicable.

[0105] The scheduled packaging time could be after a new struct is generated, after one or more new object-relational mapping codes are added to the operation method set, or at a fixed time interval, such as every 2 minutes.

[0106] Whether the predetermined packaging conditions are met can be determined by checking whether a new structure is generated, or by checking the state of the operation method set.

[0107] For example, in one embodiment, the predefined packaging condition is that after the last packaging, discrete object relation mapping code is added to the operation method set, and all discrete object relation mapping code is added to the operation method set.

[0108] Figure 7 An exemplary schematic diagram of an object-relational mapping code generation apparatus provided in an embodiment of this application is shown. Figure 7 As shown, the object-relational mapping (ORM) code generation device 700 may include at least: an acquisition module 710, a determination module 720, a mapping module 730, and a generation module 740. Specifically: the acquisition module 710 is used to acquire a database address; the determination module 720 is used to determine database information based on the database address; the mapping module 730 is used to map database tables into structures according to a preset mapping template; and the generation module 740 is used to generate ORM code for each structure according to a preset operation template, wherein the ORM code is used to operate the structure to perform operations on the database.

[0109] In one possible implementation, the mapping module specifically includes: a parsing submodule, used to parse the database information to obtain the data table structure, data table field types, and data table fields; and a mapping submodule, used to map the data table fields into structure fields according to the mapping template, the data table structure, and the data table field types, thereby generating a structure.

[0110] In one possible implementation, the mapping submodule specifically includes: a frame unit, used to convert the data table structure into a structure frame according to the mapping template; and a field unit, used to convert the data table fields into structure fields according to the mapping template and the data table field types, thereby generating a structure.

[0111] In one possible implementation, the field unit specifically includes: a conversion subunit, used to convert the data table field into a MySQL defined field according to the data table field type; and a mapping subunit, used to map the MySQL defined field into a structure field according to the mapping template, thereby generating a structure.

[0112] In one possible implementation, the generation module specifically includes: an instance submodule, used to generate a MySQL instance for the structure according to the preset operation template; and a code submodule, used to generate corresponding object-relational mapping code based on the MySQL instance.

[0113] In one possible implementation, the object-relational mapping code generation device further includes: a classification module for classifying the object-relational mapping code and generating an operation method set; and a packaging module for packaging the operation method set and generating a mapping data packet; the mapping data packet is used to transmit the operation methods.

[0114] In one possible implementation, the object relation mapping code generation device further includes: a timing module, used to determine whether there is discrete object relation mapping code at a predetermined classification time, wherein the discrete object relation mapping code is an object relation mapping code that does not belong to the operation method set; and an adding module, used to add the discrete object relation mapping code to the operation method set if there is discrete object relation mapping code.

[0115] In one possible implementation, the packaging module specifically includes: a detection submodule, used to determine whether the predetermined packaging conditions are met at each predetermined packaging time; and a packaging submodule, used to package the operation method set and generate a mapping data packet if the predetermined packaging conditions are met.

[0116] The embodiments of this application strictly map database objects to corresponding structures, avoiding the tedious task of manually defining structures, improving the efficiency of database structure definition, and avoiding various problems caused by incompatibility between structures and database structures. Simultaneously, a unified set of object-relational mapping (ORM) code is generated for each object. This ORM code is compatible with the operation syntax of various mainstream databases, ensuring consistent behavior across all objects and improving software stability. Since both structure and ORM code are automatically generated, the problem of the huge workload and low development efficiency that developers need to complete manually in existing database development processes is solved.

[0117] It should be noted that the object-relational mapping code generation device provided in the above embodiments is only illustrated by the division of the above functional modules when executing the object-relational mapping code generation method. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the wireless screen projection connection device and the wireless screen projection connection method embodiment provided in the above embodiments belong to the same concept, and the implementation process is detailed in the method embodiment, which will not be repeated here.

[0118] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0119] Please see Figure 8 This is a schematic diagram of the structure of an object-relational mapping code generation device provided in an embodiment of this application. Figure 8 As shown, the object relational mapping code generation device 80 may include: at least one processor 801, at least one network interface 804, user interface 803, memory 805, and at least one communication bus 802.

[0120] The communication bus 802 is used to enable communication between these components.

[0121] The user interface 803 may include a display screen and a camera. Optionally, the user interface 803 may also include a standard wired interface and a wireless interface.

[0122] The network interface 804 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).

[0123] The processor 801 may include one or more processing cores. The processor 801 connects various parts within the object-relational mapping code generation device 80 using various interfaces and lines. It executes various functions of the electronic device 80 and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 805, and by calling data stored in memory 805. Optionally, the processor 801 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 801 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor 801.

[0124] The memory 805 may include random access memory (RAM) or read-only memory. Optionally, the memory 805 may include a non-transitory computer-readable storage medium. The memory 805 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 805 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 805 may also be at least one storage device located remotely from the aforementioned processor 801. Figure 8 As shown, the memory 805, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an object-relational mapping code generation application.

[0125] exist Figure 8In the object-relational mapping (ORM) code generation apparatus 80 shown, the user interface 803 is mainly used to provide an input interface for the user and to obtain the user's input data; while the processor 801 can be used to call the ORM code generation application stored in the memory 805 and specifically perform the following operations:

[0126] A processor and a memory; wherein the memory stores a computer program adapted to be loaded and executed by the processor: obtaining a database address; determining database information based on the database address; mapping database tables to structures according to a preset mapping template and the database information; generating object-relational mapping code for the structures according to a preset operation template, the object-relational mapping code being used to operate the structures to operate the database.

[0127] In one possible implementation, when the processor maps a database table into a structure based on a preset mapping template and the database information, it specifically performs the following steps: parsing the database information to obtain the table structure, table field types, and table fields; and mapping the table fields into structure fields based on the mapping template, the table structure, and the table field types to generate a structure.

[0128] In one possible implementation, the processor maps the data table fields to structure fields based on the mapping template, the data table structure, and the data table field types. When generating the structure, the processor specifically performs the following steps: converting the data table structure into a structure frame based on the mapping template; and converting the data table fields into structure fields based on the mapping template and the data table field types to generate the structure.

[0129] In one possible implementation, the processor converts the data table fields into structure fields based on the mapping template and the data table field types. When generating the structure, the processor specifically performs the following steps: converting the data table fields into MySQL defined fields based on the data table field types; mapping the MySQL defined fields into structure fields based on the mapping template, and generating the structure.

[0130] In one possible implementation, when the processor generates object-relational mapping code for the structure according to a preset operation template, it specifically performs the following: generating a MySQL instance for the structure according to the preset operation template; and generating corresponding object-relational mapping code based on the MySQL instance.

[0131] In one possible implementation, before the processor generates operation methods for each structure according to the operation template, it is further configured to: classify the object relational mapping code to generate an operation method set; package the operation method set to generate a mapping data packet; and use the mapping data packet to transmit the operation methods.

[0132] In one possible implementation, after classifying the object-relational mapping code and generating an operation method set, the object-relational mapping code generation method further includes: at each predetermined classification time, determining whether there is discrete object-relational mapping code, which is object-relational mapping code that does not belong to the operation method set; if there is discrete object-relational mapping code, then adding the discrete object-relational mapping code to the operation method set.

[0133] In one possible implementation, the step of packaging the operation method set to generate a mapping data packet specifically includes: determining whether a predetermined packaging condition is met at each predetermined packaging time; if the predetermined packaging condition is met, packaging the operation method set to generate a mapping data packet.

[0134] The embodiments of this application strictly map database objects to corresponding structures, avoiding the tedious task of manually defining structures, improving the efficiency of database structure definition, and avoiding various problems caused by incompatibility between structures and database structures. Simultaneously, a unified set of object-relational mapping (ORM) code is generated for each object. This ORM code is compatible with the operation syntax of various mainstream databases, ensuring consistent behavior across all objects and improving software stability. Since both structure and ORM code are automatically generated, the problem of the huge workload and low development efficiency that developers need to complete manually in existing database development processes is solved.

[0135] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform the above-described instructions. Figures 2-6 One or more steps in the illustrated embodiment. If the constituent modules of the above-described object-relational mapping code generation device are implemented as software functional units and sold or used as independent products, they can be stored in the computer-readable storage medium.

[0136] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state drives (SSDs)).

[0137] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The aforementioned storage medium includes various media capable of storing program code, such as Read Only Memory (ROM), Random Access Memory (RAM), magnetic disks, or optical disks. Unless otherwise specified, the technical features of this embodiment and its implementation schemes can be combined arbitrarily.

[0138] The embodiments described above are merely preferred embodiments of this application and are not intended to limit the scope of this application. Any modifications and improvements made by those skilled in the art to the technical solutions of this application without departing from the spirit of this application should fall within the protection scope defined by the claims of this application.

Claims

1. An object-relational mapping code generation method characterized by, The method comprises the following steps: obtaining a database address; determining database information according to the database address; mapping a data table of the database into a structure according to a preset mapping template and the database information; generating an object-relational mapping code for the structure according to a preset operation template, the object-relational mapping code being used for operating the structure to operate the database; wherein the step of mapping the data table of the database into the structure according to the preset mapping template and the database information comprises the following steps: analyzing the database information to obtain a data table structure, a data table field type and a data table field; mapping the data table field into a structure field according to the mapping template, the data table structure and the data table field type, and generating a structure.

2. The object-relational mapping code generation method of claim 1, wherein, The step of mapping the data table field into the structure field according to the mapping template, the data table structure and the data table field type, and generating a structure comprises the following steps: converting the data table structure into a structure framework according to the mapping template; converting the data table field into a structure field according to the mapping template and the data table field type, and generating a structure.

3. The object-relational mapping code generation method of claim 2, wherein, The step of converting the data table field into the structure field according to the mapping template and the data table field type, and generating a structure comprises the following steps: converting the data table field into a MySQL definition field according to the data table field type; mapping the MySQL definition field into a structure field according to the mapping template, and generating a structure.

4. The object-relational mapping code generation method of claim 1, wherein, The step of generating the object-relational mapping code for the structure according to the preset operation template comprises the following steps: generating a MySQL instance for the structure according to the preset operation template; generating a corresponding object-relational mapping code based on the MySQL instance.

5. The object-relational mapping code generation method of claim 1, wherein, After the step of generating the object-relational mapping code for the structure according to the preset operation template, the method further comprises the following steps: classifying the object-relational mapping code to generate an operation method set; packing the operation method set to generate a mapping data packet; the mapping data packet is used for transmitting the operation method.

6. The object-relational mapping code generation method of claim 5, wherein, After the step of classifying the object-relational mapping code to generate the operation method set, the method further comprises the following steps: determining whether there is a discrete object-relational mapping code every predetermined classification time, the discrete object-relational mapping code being an object-relational mapping code not belonging to the operation method set; if there is a discrete object-relational mapping code, adding the discrete object-relational mapping code to the operation method set.

7. The object-relational mapping code generation method of claim 5, wherein, The step of packing the operation method set to generate the mapping data packet comprises the following steps: determining whether a predetermined packing condition is met every predetermined packing time; if the predetermined packing condition is met, packing the operation method set to generate the mapping data packet.

8. An object-relational mapping code generation apparatus, characterized by comprising: The method comprises the following steps: an obtaining module, configured to obtain a database address; a determining module, configured to determine database information according to the database address; a mapping module, configured to map a data table of the database into a structure according to a preset mapping template; The generating module is configured to generate object-relational mapping code for each of the structure bodies according to a preset operation template, the object-relational mapping code being used for operating the structure bodies to operate the database. The mapping module specifically comprises: The parsing submodule is configured to parse the database information to obtain a data table structure, a data table field type, and a field of the data table. The mapping submodule is configured to map the data table field into a structure body field according to the mapping template, the data table structure, and the data table field type, and generate a structure body.

9. The object-relational mapping code generation apparatus of claim 8, wherein, The mapping submodule specifically comprises: The framework unit is configured to convert the data table structure into a structure body framework according to the mapping template. The field unit is configured to convert the data table field into a structure body field according to the mapping template and the data table field type, and generate a structure body.

10. The object-relational mapping code generation apparatus of claim 9, wherein, The field unit specifically comprises: The conversion subunit is configured to convert the data table field into a MySQL definition field according to the data table field type. The mapping subunit is configured to map the MySQL definition field into a structure body field according to the mapping template, and generate a structure body.

11. The object-relational mapping code generation apparatus of claim 8, wherein, The generating module specifically comprises: The instance submodule is configured to generate a MySQL instance for the structure body according to the preset operation template. The code submodule is configured to generate corresponding object-relational mapping code based on the MySQL instance.

12. The object-relational mapping code generation apparatus of claim 8, wherein, The object-relational mapping code generation apparatus further comprises: The classification module is configured to classify the object-relational mapping code to generate a set of operation methods. The packaging module is configured to package the set of operation methods to generate a mapping data packet; the mapping data packet is used to transmit the operation methods.

13. The object-relational mapping code generation apparatus of claim 12, wherein, The object-relational mapping code generation apparatus further comprises: The timing module is configured to determine whether there is discrete object-relational mapping code at a predetermined classification time, the discrete object-relational mapping code being object-relational mapping code that does not belong to the set of operation methods. The joining module is configured to add the discrete object-relational mapping code to the set of operation methods if there is discrete object-relational mapping code.

14. The object-relational mapping code generation apparatus of claim 12, wherein, The packaging module specifically comprises: The detection submodule is configured to determine whether a predetermined packaging condition is met at a predetermined packaging time. The packaging submodule is configured to package the set of operation methods to generate a mapping data packet if the predetermined packaging condition is met.

15. An electronic device, comprising: The computer storage medium stores a plurality of instructions, the instructions being adapted to be loaded and executed by the processor to perform the method steps of any one of claims 1-7. ​ 16. A computer storage medium, comprising, ​

Citation Information

Patent Citations

  • Log processing code generation method and device, computer system and storage medium

    CN111177089A

  • Code automatic generation method and device, storage medium and terminal equipment

    CN114968214A