CN116185389A - Code generation method and device, electronic equipment and medium - Google Patents

Code generation method and device, electronic equipment and medium Download PDF

Info

Publication number
CN116185389A
CN116185389A CN202310033586.0A CN202310033586A CN116185389A CN 116185389 A CN116185389 A CN 116185389A CN 202310033586 A CN202310033586 A CN 202310033586A CN 116185389 A CN116185389 A CN 116185389A
Authority
CN
China
Prior art keywords
code
database table
generating
database
row
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310033586.0A
Other languages
Chinese (zh)
Inventor
韩永成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur General Software Co Ltd
Original Assignee
Inspur General Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur General Software Co Ltd filed Critical Inspur General Software Co Ltd
Priority to CN202310033586.0A priority Critical patent/CN116185389A/en
Publication of CN116185389A publication Critical patent/CN116185389A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a code generation method, a code generation device, electronic equipment and a code generation medium, belongs to the technical field of computers, and is used for solving the technical problems of complex code generation process and low code generation efficiency caused by excessive repeated operation of the existing code generation method. The method comprises the following steps: acquiring a database table of a code to be generated according to pre-configured database connection information; generating a corresponding data model according to the database table; and generating codes corresponding to the database table according to the data model and a preset code template. The method has the advantages that the corresponding complete set of codes can be generated according to actual needs, the development efficiency of the system is improved, the operation is simple and quick, the software output efficiency of enterprises can be improved, engineers can pay more attention to business logic, larger social value is created, much effort of developers is saved, manual errors are reduced, the developers do not waste much effort on related operations of a database, and therefore the code generation efficiency is improved.

Description

Code generation method and device, electronic equipment and medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a code generating method, a device, an electronic apparatus, and a medium.
Background
In the process of software development, various code generation tools are widely used for increasing the stability of a system, reducing the development and maintenance cost of software and improving the development efficiency. In the process of writing codes, repeated work is often involved, repeated processing of a large number of identical codes is a piece of tedious manual labor, the process of copying and pasting cannot guarantee uniformity and standardization of the codes, and the correctness of the codes in the process of copying cannot be guaranteed.
In the existing code generation method, a user is required to select repeated contents for many times in the code generation process, even the code is required to be generated by inputting corresponding instructions through a keyboard, the code generation process is complicated, and the generation efficiency is low.
Disclosure of Invention
The embodiment of the application provides a code generation method, a code generation device, electronic equipment and a medium, which are used for solving the following technical problems: the existing code generation method is excessive in repeated operation, so that the code generation process is complicated, and the code generation efficiency is low.
The embodiment of the application adopts the following technical scheme:
in one aspect, an embodiment of the present application provides a code generating method, including: acquiring a database table of a code to be generated according to pre-configured database connection information; generating a corresponding data model according to the database table; and generating codes corresponding to the database table according to the data model and a preset code template.
In a possible implementation manner, according to the pre-configured database connection information, a database table of the code to be generated is obtained, which specifically includes: connecting the corresponding databases according to the preset database connection information; the database connection information at least comprises a database name, a database type, a user name and a user password; searching a database table of the code to be generated in the database; acquiring data and metadata of the database table; wherein the row data is data included in each row of tables in the database table; the metadata is used to describe attribute information of each line of data.
In a possible implementation manner, the generating a corresponding data model according to the table information of the database table specifically includes: determining the metadata corresponding to each group of data; the metadata at least comprises a keyword, wherein the keyword comprises whether the keyword is identification information, a primary key, a field size, a field type and a field name; and filling the row data into row information, filling the metadata into column information of corresponding row data, and generating the data model.
In a possible implementation manner, before generating the code corresponding to the database table according to the data model and the preset code template, the method further includes: determining a fixed field of a target keyword; determining a variable field of the target keyword and a position of the variable field in the fixed field; setting a preset code template according to the fixed field and the variable field; wherein the preset code template corresponds to the target keyword.
In a possible implementation manner, the generating the code corresponding to the database table according to the data model and the preset code template specifically includes: determining keywords corresponding to each group of row information in the data model; matching the keywords corresponding to each group of row information with the target keywords of each preset code template, and determining the preset code templates corresponding to each group of row information; filling the row data corresponding to each group of row information into the variable fields of the corresponding preset code templates to obtain corresponding row codes; and combining all the generated row codes into codes corresponding to the database table.
In a possible implementation manner, after generating the code corresponding to the database table according to the data model and a preset code template, the method further includes: determining the service type of the database table; determining a service fixing template corresponding to the service type; wherein, the service fixed template defines a fixed code format corresponding to the service type; and adding the service fixed template into the generated code to obtain a standard code corresponding to the service type.
In a possible implementation manner, after generating the code corresponding to the database table according to the data model and a preset code template, the method further includes: determining a translation type of the code; the code is converted to a format of the translation type.
In a second aspect, embodiments of the present application further provide a code generating apparatus, where the apparatus includes: the database table acquisition unit is used for acquiring a database table of a code to be generated according to the pre-configured database connection information; the data model generating unit is used for generating a corresponding data model according to the table information of the database table; and the processing unit is used for generating codes corresponding to the database table according to the data model and a preset code template.
In a third aspect, embodiments of the present application further provide a code generating electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a code generation method according to any one of the embodiments described above.
In a fourth aspect, embodiments of the present application further provide a computer readable medium having stored thereon computer instructions that, when executed by a processor, enable the processor to perform a code generation method according to any one of the above embodiments.
Compared with the prior art, the code generation method, the device, the electronic equipment and the medium provided by the embodiment of the application acquire the database table of the code to be generated from the database through the pre-configured database link information, generate the data model according to the database table, generate the code according to the data model and the preset code template, convert the database table of the code to be generated into the data model, generate the code by using the preset code template, save much effort of a developer, reduce manual errors, enable the developer not to waste excessive effort on related operations of the database, and further improve the efficiency of code generation.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments described in the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. In the drawings:
fig. 1 is a flowchart of a code generation method provided in an embodiment of the present application;
fig. 2 is a flowchart of a method for setting a preset code template according to an embodiment of the present application
Fig. 3 is a schematic structural diagram of a code generating device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a code generating electronic device according to an embodiment of the present application.
Detailed Description
In order to better understand the technical solutions in the present application, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
The embodiment of the application provides a code generation method, as shown in fig. 1, the code generation method specifically includes steps S110-S130:
s110, acquiring a database table of the code to be generated according to the pre-configured database connection information.
Specifically, the corresponding database is connected according to the pre-configured database connection information. The database connection information is related information required for downloading the database table, is mainly described by data configured by the database, and can comprise a database name, a type, a user name, a password, a name and the like of the server.
Further, a database table of the code to be generated is searched in the database, and row data and metadata of the database table are acquired. The database table characterizes the underlying configuration of the table in the database. The row data is the data included in each row of tables in the database table; metadata is used to describe attribute information of each line of line data.
As one possible implementation, the database table may include, but is not limited to, field information of the table in the database, the field information including at least one of a field name, a field type, and a field attribute of each table field in the table, and metadata including at least one of a table name, and a primary foreign key relationship of the table. The database may be any type of database such as oracle, mysql, sqlserver, which is not limited to the embodiments of the present disclosure.
S120, generating a corresponding data model according to the database table.
Specifically, the data model is used for describing the demand information in the system, is a basic model of the code automatic generation framework, and can quickly generate codes by converting the database table into the data model under the framework. The data model frame includes row information and column information.
Firstly, determining metadata corresponding to each group of data; the metadata at least comprises a keyword, wherein the keyword comprises whether the keyword is identification information, a primary key, a field size, a field type and a field name. And then filling the row data into the row information, and filling the metadata into the column information of the corresponding row data to generate a data model.
Each row of the database table corresponds to a set of row data, the row of data in the database table being configured to describe the contents of the database, the row of data in each row of the database table being configured to describe the data included in that row. Metadata describes the relevant attributes of the line data.
In an embodiment of the present invention, the metadata includes at least one keyword, and the keyword includes whether it is identification information, whether it is a primary key, a size, a type, and a name. The structure of the database table and the view is mainly described by table and view generation metadata in the database, and is described in column information, for example, m columns of information are "whether the data is a primary key", if the row of the nth row is a primary key, the data in the nth row in the database table is marked by the metadata, and the row of the data is marked as the primary key.
S130, generating codes corresponding to the database table according to the data model and a preset code template.
Specifically, the preset code template is created by pre-written sample codes or selected sample codes, and the preset code template comprises fixed content and content for filling according to data in the data model. First, a fixed field of a target key is determined, and then a variable field of the target key and a position of the variable field in the fixed field are determined. And finally, setting a preset code template according to the fixed field and the variable field. The preset code template corresponds to the target keyword.
Further, keywords corresponding to each set of row information in the data model are determined. And then matching the keywords corresponding to each group of row information with the target keywords of each preset code template, and determining the preset code templates corresponding to each group of row information. And filling the row data corresponding to each group of row information into the variable fields of the corresponding preset code templates to obtain corresponding row codes. And finally, combining all the generated row codes into codes corresponding to the database table.
In the code generation process, repeated and fixed codes are not required to be written manually repeatedly based on the code template, and the codes can be obtained by filling data in the data model into the code template, so that the generated codes are ensured to have standardability and accuracy, and the code generation efficiency is effectively improved.
Each keyword corresponds to a preset code template, and the keywords corresponding to the row information are used for identifying the preset code templates needed to be used by the row data. In the method, when the variable fields corresponding to the difference content replacement identifications are determined, the correct preset code templates can be selected according to the keywords, so that the content filling is further ensured to be correct, and a precondition guarantee is provided for automatic generation of subsequent codes.
Specifically, the keywords may include: class name, one or more attributes of a class, type of attribute, name of attribute, package name, reference to a single class file, reference set of multiple class files, table name of a database, primary key type, column name in a database, attribute data type in a table, etc.
Further, after generating the code, the method further comprises the steps of:
and determining the service type of the database table, determining a service fixed template corresponding to the service type, and finally adding the service fixed template into the generated code.
The service type may represent a service scenario, such as java, corresponding to the data table when the data table is converted into the code, and in the corresponding service type, the code needs to include some fixed formats of the service type, such as a fixed prefix or a fixed suffix, so that on the basis of generating the code, a service fixed template including the fixed format of the service type is added to the code, so as to meet the requirements of different service scenarios. In particular, the business fixed templates may be set according to the name and path containing the ORM component, the solution, the namespace of the system, and the development tools and versions thereof.
As a possible implementation, the present application may also determine the translation type of the code and then convert the generated code into a format of the translation type. The generation of code may be accomplished by a code generation engine. The code generation engine is a stand-alone application and occupies a core position in the overall code generation framework. The code generation engine generates codes according to different inter-code templates based on a data model of the management information system, so that basic data query modification, deletion, addition and other operations are completed. In addition, codes can be converted into different transition types, so that more use scenes can be adapted.
The embodiment of the application provides a code generation method, a device, electronic equipment and a medium, wherein a database table of a code to be generated is obtained from a database through pre-configured database link information, a data model is generated according to the database table, and the code is generated according to the data model and a pre-set code template.
Fig. 2 is a flowchart of a method for setting a preset code template according to an embodiment of the present application, as shown in fig. 2, where the method includes:
s210, determining a fixed field of the target keyword.
S220, determining the position of the variable field of the target key word in the fixed field.
S230, setting a preset code template according to the fixed field and the variable field.
Before the preset code template is constructed, keywords and meanings thereof are defined firstly so as to define the preset code template, ensure that styles of the preset code template are consistent, and provide feasible conditions for unified management of the preset code template.
The preset code template is actually in an abstract code format, and a designer only needs to pre-construct one code template for a certain type and provide program codes to generate various specific types, so that the programming efficiency is effectively improved. The code template may generate specific classes and their objects by instantiating the class template.
In the code generation process, variable fields corresponding to the difference content replacement identifications in the code generation templates are determined, and data filling is carried out in the variable fields so as to generate codes according to the processed code templates, so that in the code generation process, automatic generation of codes can be realized by filling replacement of the difference content based on the code templates.
As a possible implementation manner, the fixed field and the variable field can be distinguished by extracting the difference content and the shared content from the sample code, wherein the variable field refers to a field which needs to be changed and adjusted in the process of generating the code, and the fixed field refers to some shared content which does not need to be changed in the process of generating the code. Specifically, the target sample code can be processed through the Velocity template engine, and of course, the sample code can also be processed through the Freemarker template engine or other custom template engines, and the code template is created based on the difference content and the shared content, so that the creation efficiency of the code template is ensured.
Fig. 3 is a schematic structural diagram of a code generating device according to an embodiment of the present invention, where, as shown in fig. 3, the device includes:
a database table obtaining unit 310, configured to obtain a database table of a code to be generated according to the pre-configured database connection information;
a data model generating unit 320, configured to generate a corresponding data model according to table information of the database table;
and the processing unit 330 is configured to generate a code corresponding to the database table according to the data model and a preset code template.
Optionally, the database table obtaining unit 310 is configured to perform: connecting the corresponding databases according to the preset database connection information; the database connection information at least comprises a database name, a database type, a user name and a user password; searching a database table of the code to be generated in the database; acquiring data and metadata of the database table; wherein the row data is data included in each row of tables in the database table; the metadata is used to describe attribute information of each line of data.
Optionally, the data model generating unit 320 is configured to perform: determining the metadata corresponding to each group of data; the metadata at least comprises a keyword, wherein the keyword comprises whether the keyword is identification information, a primary key, a field size, a field type and a field name; and filling the row data into row information, filling the metadata into column information of corresponding row data, and generating the data model.
Accordingly, as shown in fig. 3, the apparatus further includes: a preset code template setting unit 340;
a preset code template setting unit 340 for setting a preset code template by:
determining a fixed field of a target keyword;
determining a variable field of the target keyword and a position of the variable field in the fixed field;
setting a preset code template according to the fixed field and the variable field; wherein the preset code template corresponds to the target keyword.
Optionally, the processing unit 330 is configured to perform: determining keywords corresponding to each group of row information in the data model; matching the keywords corresponding to each group of row information with the target keywords of each preset code template, and determining the preset code templates corresponding to each group of row information; filling the row data corresponding to each group of row information into the variable fields of the corresponding preset code templates to obtain corresponding row codes; and combining all the generated row codes into codes corresponding to the database table.
Optionally, the processing unit 330 is further configured to perform: determining the service type of the database table; determining a service fixing template corresponding to the service type; wherein, the service fixed template defines a fixed code format corresponding to the service type; and adding the service fixed template into the generated code to obtain a standard code corresponding to the service type.
Optionally, the processing unit 330 is further configured to perform: determining a translation type of the code; the code is converted to a format of the translation type.
It should be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the code generating apparatus. In other embodiments of the invention, the code generating means may comprise more or less components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The content of information interaction and execution process between the units in the device is based on the same conception as the embodiment of the method of the present invention, and specific content can be referred to the description in the embodiment of the method of the present invention, which is not repeated here.
The code generating device can generate a corresponding complete set of codes according to actual needs, improves the development efficiency of the system, is simple and quick to operate, can improve the software output efficiency of enterprises, can enable engineers to pay more attention to business logic, and creates larger social value instead of spending time in repeated simple work.
Fig. 4 shows a schematic diagram of a code-generating electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable electronic devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 4, the electronic device 10 includes at least one processor 11, and a memory, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, etc., communicatively connected to the at least one processor 11, in which the memory stores a computer program executable by the at least one processor, and the processor 11 may perform various appropriate actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from the storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 may also be stored. The processor 11, the ROM 12 and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
Various components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, etc.; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other electronic devices via a computer network, such as the internet, and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The processor 11 performs the respective methods and processes described above, for example, a code generation method.
In some embodiments, the code generation method may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the code generation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the code generation method in any other suitable way (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for carrying out methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be implemented. The computer program may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or electronic device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage electronic device, a magnetic storage electronic device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service are overcome.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present invention may be performed in parallel, sequentially, or in a different order, so long as the desired results of the technical solution of the present invention are achieved, and the present invention is not limited herein.
All embodiments in the application are described in a progressive manner, and identical and similar parts of all embodiments are mutually referred, so that each embodiment mainly describes differences from other embodiments. In particular, for apparatus, electronic devices, non-volatile computer storage medium embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to the description of the method embodiments.
The foregoing describes specific embodiments of the present application. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and variations of the embodiments of the present application will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present application should be included in the scope of the claims of the present application.

Claims (10)

1. A code generation method, the method comprising:
acquiring a database table of a code to be generated according to pre-configured database connection information;
generating a corresponding data model according to the database table;
and generating codes corresponding to the database table according to the data model and a preset code template.
2. The method for generating codes according to claim 1, wherein the step of obtaining the database table of the codes to be generated according to the pre-configured database connection information comprises the steps of:
connecting the corresponding databases according to the preset database connection information; the database connection information at least comprises a database name, a database type, a user name and a user password;
searching a database table of the code to be generated in the database;
acquiring data and metadata of the database table; wherein the row data is data included in each row of tables in the database table; the metadata is used to describe attribute information of each line of data.
3. The code generating method according to claim 2, wherein the generating of the corresponding data model based on the table information of the database table specifically includes:
determining the metadata corresponding to each group of data; the metadata at least comprises a keyword, wherein the keyword comprises whether the keyword is identification information, a primary key, a field size, a field type and a field name;
and filling the row data into row information, filling the metadata into column information of corresponding row data, and generating the data model.
4. The method of claim 1, wherein before generating the code corresponding to the database table according to the data model and a preset code template, the method further comprises:
determining a fixed field of a target keyword;
determining a variable field of the target keyword and a position of the variable field in the fixed field;
setting a preset code template according to the fixed field and the variable field; wherein the preset code template corresponds to the target keyword.
5. The code generation method according to claim 1, wherein generating the code corresponding to the database table according to the data model and a preset code template specifically includes:
determining keywords corresponding to each group of row information in the data model;
matching the keywords corresponding to each group of row information with the target keywords of each preset code template, and determining the preset code templates corresponding to each group of row information;
filling the row data corresponding to each group of row information into the variable fields of the corresponding preset code templates to obtain corresponding row codes;
and combining all the generated row codes into codes corresponding to the database table.
6. The code generation method according to claim 1, wherein after generating the code corresponding to the database table according to the data model and a preset code template, the method further comprises:
determining the service type of the database table;
determining a service fixing template corresponding to the service type; wherein, the service fixed template defines a fixed code format corresponding to the service type;
and adding the service fixed template into the generated code to obtain a standard code corresponding to the service type.
7. The code generation method according to claim 1, wherein after generating the code corresponding to the database table according to the data model and a preset code template, the method further comprises:
determining a translation type of the code;
the code is converted to a format of the translation type.
8. A code generating apparatus, the apparatus comprising:
the database table acquisition unit is used for acquiring a database table of a code to be generated according to the pre-configured database connection information;
the data model generating unit is used for generating a corresponding data model according to the table information of the database table;
and the processing unit is used for generating codes corresponding to the database table according to the data model and a preset code template.
9. A code generating electronic device, the electronic device comprising:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a code generation method according to any one of claims 1-7.
10. Computer readable medium, characterized in that it has stored thereon computer instructions which, when executed by a processor, enable the processor to perform a code generation method according to any of claims 1-7.
CN202310033586.0A 2023-01-10 2023-01-10 Code generation method and device, electronic equipment and medium Pending CN116185389A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310033586.0A CN116185389A (en) 2023-01-10 2023-01-10 Code generation method and device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310033586.0A CN116185389A (en) 2023-01-10 2023-01-10 Code generation method and device, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN116185389A true CN116185389A (en) 2023-05-30

Family

ID=86432026

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310033586.0A Pending CN116185389A (en) 2023-01-10 2023-01-10 Code generation method and device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN116185389A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117389542A (en) * 2023-09-06 2024-01-12 苏州数设科技有限公司 Industrial software construction method and device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117389542A (en) * 2023-09-06 2024-01-12 苏州数设科技有限公司 Industrial software construction method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN114816578B (en) Program configuration file generation method, device and equipment based on configuration table
CN116185389A (en) Code generation method and device, electronic equipment and medium
CN113127357B (en) Unit test method, apparatus, device, storage medium, and program product
CN114168119B (en) Code file editing method, device, electronic equipment and storage medium
CN116414814A (en) Data checking method, device, equipment, storage medium and program product
CN116303461A (en) Component library creation method and device, electronic equipment and storage medium
CN116009847A (en) Code generation method, device, electronic equipment and storage medium
CN115577689A (en) Table component generation method, device, equipment and medium
CN116011955A (en) Robot flow automation demand realization method, device, equipment and storage medium
CN115454971A (en) Data migration method and device, electronic equipment and storage medium
CN115981657A (en) Code generation method and device, electronic equipment and readable medium
CN117271840B (en) Data query method and device of graph database and electronic equipment
CN116755684B (en) OAS Schema generation method, device, equipment and medium
CN113220710B (en) Data query method, device, electronic equipment and storage medium
CN117667976A (en) Data processing method, device, equipment and storage medium
CN117608575A (en) Application development method, system, equipment and storage medium
CN117194435A (en) Index data updating method, device, equipment and storage medium
CN118012897A (en) Heterogeneous database grammar conversion method, device, equipment and storage medium
CN114443035A (en) Code generation method for application program, code generator, electronic device, and medium
CN115454977A (en) Data migration method, device, equipment and storage medium
CN117632734A (en) Performance test method of database, electronic equipment and storage medium
CN115495368A (en) Data testing method and device and electronic equipment
CN116841982A (en) Database migration method, device, equipment, storage medium and program product
CN116401269A (en) Data query method and device, electronic equipment and storage medium
CN117610580A (en) Instruction identification method and device based on large model, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination