Background
The existing generation tool of the dynamic data structure can only generate a simple single-table data structure so as to meet simple business logic; for enterprise structures, equipment structures and the like, managing complex scenes, generally associating single-table data structures and generating a tree-type structure table; when the tree structure table is generated, developers need to modify the sql codes manually, operation is complex, modification errors and omissions are easy to occur, and time cost is high; in addition, the tree structure table generated in this way is inflexible in data structure, and cannot be modified for different application scenarios.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for generating a tree structure table, and an electronic device, where a database is directly processed, the operation is simple, the time cost is low, and meanwhile, the data structure of the tree structure table can be flexibly modified for different application scenarios.
In a first aspect, an embodiment of the present invention provides a method for generating a tree structure table, where the method is applied to a database management system, and the method includes: receiving an initial sql file; generating an initial tree structure table based on the initial sql file; receiving a configuration sql file aiming at an initial tree structure table; configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table; configuring an initial tree structure table based on the configuration sql file to obtain a tree structure table; wherein the tree structure table comprises a plurality of levels of nodes, each node comprising one or more child nodes.
Further, the database management system is in communication connection with the server; the server is in communication connection with the client; the step of receiving an initial sql file comprises: and receiving the initial sql file sent by the server through the database interface program.
Further, the initial sql file is generated by: the client responds to a generation instruction aiming at the initial tree structure table, and generates a first json file based on the table structure information and the data structure information of the initial tree structure table; and the client responds to a saving instruction aiming at the initial tree structure table, and sends the first json file to the server so that the server converts the first json file into an initial sql file.
Further, the database management system is in communication connection with the server; the server is in communication connection with the client; the step of receiving a configuration sql file for the initial tree structure table comprises: and receiving the configuration sql file sent by the server through a database interface program.
Further, the configuration sql file is generated by the following method: processing the initial tree structure table into a second json file after receiving a query instruction of the initial tree structure table; sending the second json file to the client so that the client responds to modification operation aiming at the second json file and generates a configuration json file; sending the configuration json file to a server so that the server converts the second json file into a configuration sql file; wherein the modifying operation comprises: modifying, adding or deleting the information of the corresponding table structure and/or data structure in the second json file; the client is further used for dynamically rendering the page provided by the client according to the second json file and displaying the initial tree structure table on the page.
Further, the tree structure table comprises a plurality of types of nodes; wherein, the nodes or sub-nodes with the same type are corresponding to the same dictionary table; the nodes and the child nodes are used for storing the basic data of the corresponding types.
Further, the step of generating an initial tree structure table based on the initial sql file includes: executing the initial sql file in a transaction operation mode to generate an initial tree structure table; configuring an initial tree structure table based on the configuration sql file to obtain a tree structure table, wherein the step comprises the following steps: executing the configuration sql file in a transaction operation mode; and changing the table structure and/or the data structure of the initial tree structure table to obtain the tree structure table.
In a second aspect, an embodiment of the present invention provides a device for generating a tree structure table, where the device is disposed in a database management system, and the device includes: the system comprises an initial tree structure table generating module, a query module and a query module, wherein the initial tree structure table generating module is used for receiving an initial sql file; generating an initial tree structure table based on the initial sql file; a configuration sql file receiving module, configured to receive a configuration sql file for the initial tree structure table; configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table; the initial tree structure table configuration module is used for configuring the initial tree structure table based on the configuration sql file to obtain a tree structure table; wherein the tree structure table comprises a plurality of levels of nodes, each node comprising one or more child nodes.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, where the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the method for generating the tree structure table according to any one of the first aspect.
In a fourth aspect, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions that, when invoked and executed by a processor, cause the processor to implement a method of generating a tree structure table according to any one of the first aspect.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a method and a device for generating a tree structure table and electronic equipment, wherein the method comprises the steps of generating an initial tree structure table based on a received initial sql file; configuring an initial tree structure table based on the received configuration sql file to obtain a tree structure table; wherein configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table; the tree structure table includes a plurality of levels of nodes, each node including one or more child nodes. In the method, the initial sql file and the configured sql file can be directly processed through the database management system to obtain the tree structure table, the operation is simple, the time cost is low, and meanwhile, the method can flexibly modify the data structure of the tree structure table according to different application scenes.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The existing generation tool of the dynamic data structure can only generate a simple single-table data structure so as to meet simple business logic; for enterprise structures, equipment structures and the like, managing complex scenes, generally associating single-table data structures and generating a tree-type structure table; when the tree structure table is generated, developers need to modify the sql codes manually, operation is complex, modification errors and omissions are easy to occur, and time cost is high; in addition, the tree structure table generated by the method is inflexible in data structure and single in parameter, cannot increase the relationship among data structures in a finer granularity, and cannot be modified according to different application scenes.
In the prior art, when data is generated, a B/S (Browser/Server, Browser and Server) framework cannot check the direct table structure relationship of a database before generation, cannot reflect the relationship between table structures, cannot specify a field to increase an index after generation, and cannot prompt specific implementers to know the reason after generation fails. In addition, in the prior art, the relation between table structures is not checked during data query, only single-table query is performed, and the tree structure cascade relation is not provided, only addition, deletion, modification and check of single tables are performed, so that the existing enterprise-level huge tree structure cascade relation cannot be met. Based on this, the method and apparatus for generating a data structure table and the electronic device provided by the embodiments of the present invention may be applied to devices such as a mobile phone, a computer, a notebook, a server, and a database management system.
To facilitate understanding of the embodiment, first, a detailed description is given to a method for generating a tree structure table disclosed in the embodiment of the present invention, where the method is applied to a database management system, and the database management system is provided with a plurality of databases supporting mysql, oracle, sql server, and the like.
As shown in fig. 1, the method comprises the steps of:
step S102, receiving an initial sql file; generating an initial tree structure table based on the initial sql file;
the initial sql file comprises codes of sql language, and the initial sql file comprises data structure information and table structure information of an initial tree structure table; the data structure comprises categories such as arrays and queues, and the table structure comprises a table name, fields in the table and a record part of the table; the database may execute the initial sql file, generate a result, i.e., an initial tree structure table, displayed by the user at the front end from the information of the initial tree structure table included in the initial sql file, and store the initial tree structure table in the database.
For example, the received initial sql file may be, CREATE TABLE 'test 1 ″ (r) ((r)')
`id`varchar(10)NOT NULL DEFAULT‘1’,
`name`varchar(10)CHARACTER SET utf8,
PRIMARY KEY(`id`)USING BTREE,
) (ii) a The method comprises the information of a table name, a main key field, a coding set, a column name, a type of a column value, a field length, a decimal point number, a default value and the like of an initial tree structure table.
In addition, the initial tree structure table may include one or more nodes, each node may have one or more child nodes, and each child node may correspond to a different dictionary table. If the types of each node are inconsistent, different dictionary tables can be used for storing the basic data of each node, the method is suitable for tree structures with multiple dimensions, the data structure of each tree structure can be configured in a page, the effect and the result of specified use are achieved, and various abnormal conditions can be dealt with.
Step S104, receiving a configuration sql file aiming at the initial tree structure table; the configuration sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table;
the generated initial tree structure table has the functions of node configuration and modification, so that the generated initial tree structure table can be configured according to an actual application scene and business logic so as to change the data structure and the table structure of the initial tree structure table and modify, add or delete the node information of one or more nodes in the initial tree structure table; for example, the table name, the field name of the node, adding the node, deleting the node, changing the relationship between the data structures, and changing the relationship between the nodes, etc.
Step S106, configuring an initial tree structure table based on the configuration sql file to obtain a tree structure table; wherein the tree structure table comprises a plurality of levels of nodes, each node comprising one or more child nodes.
Specifically, the received configuration sql file is processed through a database persistent layer, the configuration sql file is executed, information needing to be changed in the initial tree structure table is changed, the changing process completely depends on the corresponding database, and finally the tree structure table is generated. The process is operated by a database, and is faster and safer than sequencing in a code structure; data cannot be lost due to the limitation of the main foreign key, and dirty data cannot be stored.
Fig. 2 is a schematic structural diagram of a tree structure table, which includes multiple levels of nodes, where node1 is a primary node, the node has a child node (node2), and node2 is a secondary node; the node2 has two child nodes (node3, node4), and node3 and node4 are tertiary nodes, wherein the right two child nodes (node5, node6) of node4, node5 and node6 are quaternary nodes.
Wherein the tree structure table further comprises a plurality of types of nodes; nodes or child nodes with the same type correspond to the same dictionary table; the nodes and the child nodes are used for storing the basic data of the corresponding types. The tree structure is suitable for multiple dimensions, the data structure of each tree structure can be guaranteed to be configured in the page, the effect and the result of specified use are achieved, and multiple abnormal conditions are responded.
The embodiment of the invention provides a method for generating a tree structure table, which is characterized in that an initial tree structure table is generated based on a received initial sql file; configuring an initial tree structure table based on the received configuration sql file to obtain a tree structure table; wherein configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table; the tree structure table includes a plurality of levels of nodes, each node including one or more child nodes. In the method, the initial sql file and the configured sql file can be directly processed through the database management system to obtain the tree structure table, the operation is simple, the time cost is low, and meanwhile, the method can flexibly modify the data structure of the tree structure table according to different application scenes.
The implementation also provides another generation method of the tree structure table, wherein the database management system is in communication connection with a server, and the server is in communication connection with a client; as shown in fig. 3, the method comprises the steps of:
step S302, receiving an initial sql file sent by a server through a database interface program;
the Database interface program may be a JDBC (Java Database Connectivity) interface program, if the language used by the Database is Java, the Database interface program may be an odbc (open Database Connectivity) interface program, if the language used by the Database is C + +, the Database interface program may be a Connector C + + interface program, and if the language adapted by the Database is phthon, the Database interface program may be a mysql-Connector interface program. The database management system is in communication connection with the server and can send or receive the sql file through a database interface program.
Wherein the initial sql file is generated by:
(1) the client responds to a generation instruction aiming at the initial tree structure table, and generates a first json file based on the table structure information and the data structure information of the initial tree structure table;
referring to the sequence diagram of the generation method of the tree structure table shown in fig. 4, the client (web) may be an operation page of a browser, an application program, or the like; specifically, the data structure and the table structure can be customized and designed by an operation page provided by a developer, a product person or a common user (user) for operating the terminal equipment, and the basic structure comprises a table name, a remark and the like; the design of the data table structure defines the file name of the data table, determines which fields are contained in the data table, the field name, the field type and the width of each field, and inputs the data into an operation page of the computer. After the design is finished, a generation button of an operation page can be clicked; the client responds to a generation instruction aiming at the initial tree structure table, and the operation page can preview and display or edit and display the initial tree structure table; and simultaneously generating a first json file based on the table structure information and the data structure information of the initial tree structure table.
For example, the first json file may be:
the tableList is a collection of the batch saving tables, wherein tableName is a table name, primaryKey is a primary key field, a coding collection of a charSet table, columns are a column collection, name is a column name, valueType, a type of a value of a column, a length column field length, decimalPoint decimal point number of bits, and a default value of default.
(2) And the client responds to a saving instruction aiming at the initial tree structure table, and sends the first json file to the server so that the server converts the first json file into an initial sql file.
After the user clicks the save button of the operation page, referring to fig. 4, the client sends the first json file to the server (server), so that the server converts the first json file into an initial sql file. Meanwhile, the server is connected with a specified database (db, data base) in the database management system, and sends the initial sql file to the specified database.
Step S304, executing the initial sql file in a transaction operation mode to generate an initial tree structure table;
after receiving the initial sql file, a designated database in the database management system usually sorts the initial sql file, and then directly performs database operation, wherein the database operation comprises transaction operation, if the operation is successful, the transaction is submitted, the initial sql file is executed, an initial tree structure table is generated, and the initial tree structure table is stored; if the operation is unsuccessful, the transaction rolls back the value server.
In addition, after the initial tree structure table is generated, the method further includes: based on the client side automatic response query operation, the designated database in the database management system corresponding to the initial tree structure sends the initial tree structure table to the client side for displaying.
Step S306, receiving a configuration sql file sent by a server through a database interface program; the configuration sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table;
the configuration sql file is generated by the following method:
(1) processing the initial tree structure table into a second json file after receiving a query instruction of the initial tree structure table;
the query instruction may be an instruction automatically triggered by the client, and is usually triggered after the initial tree structure table is generated; or it may be a user triggered query instruction at the discretion, typically at the time of re-querying the previously generated initial tree structure table. And after receiving a query instruction of the initial tree structure table, processing the initial tree structure table into a second json file.
(2) Sending the second json file to the client so that the client responds to modification operation aiming at the second json file and generates a configuration json file; sending the configuration json file to a server so that the server converts the second json file into a configuration sql file; wherein the modifying operation comprises: and modifying, adding or deleting the information of the corresponding table structure and/or data structure in the second json file.
Referring to fig. 4, a process of sending the second json file to the client is that the database sends the second json file (result) to the server first, and the server receives the second json file (result) and then corresponds to the second json file, and sends the second json file to the client.
Specifically, after receiving the second json file, the client may modify the data in the second json file, for example, the table name modification may be performed to modify 'tableName' to the table name desired by the user; also for example, the connections of a table structure may be modified, the foreign key of a given table may be modified, and the table may be associated with another table. And finally determining the modified second json file as a configuration json file. The client sends the configuration json file to the server so that the server converts the second json file into a configuration sql file.
In addition, after the second json file is sent to the client, the client is further used for dynamically rendering the page provided by the client according to the second json file and displaying the initial tree structure table on the page; in the mode, the client, the server and the database management system establish real-time connection, can place high concurrency, and can bidirectionally synchronize a data structure and a table structure to show the latest data structure for a user in real time.
Step S308, the configuration sql file is executed in a transaction operation mode; and changing the table structure and/or the data structure of the initial tree structure table to obtain the tree structure table.
After receiving the initial sql file, a designated database in the database management system usually sorts the configured sql file, then directly performs database operation, wherein the database operation comprises transaction operation, if the operation is successful, the transaction is submitted, the configured sql file is executed, the table structure and the data structure of the initial tree structure table are changed, and the tree structure table is obtained and stored; if the operation is unsuccessful, the transaction rolls back the value server. Or executing the configuration sql file, changing the table structure or the data structure of the initial tree structure table to obtain the tree structure table, storing the tree structure table, and sending the tree structure table to the client for displaying back so that the client displays the latest tree structure table in real time.
In the mode, through a simple user-defined data structure and a table structure of a user, the front-end client can automatically generate a corresponding json file, simultaneously the json file is sent to the server, the json file is converted into a language which can be executed by the database through the server, namely, an sql file, and the sql file is sent to the database to be operated so as to generate an initial tree structure table or configure the initial tree structure table. The mode of directly utilizing the database for operation is higher in sorting speed and safer than that of a code structure, and data cannot be lost. Meanwhile, different nodes in the generated tree structure table can have different data structures, and the types of each node can be completely different; in addition, the client, the server and the database are connected in real time, high concurrency can be prevented, the data structure and the table structure are synchronized in a two-way mode, and the latest data structure can be displayed for a user in real time.
Corresponding to the above method embodiment, this embodiment provides a device for generating a tree structure table, where the device is disposed in a database management system, and as shown in fig. 5, the device includes:
an initial sql file receiving module 51, configured to receive an initial sql file;
an initial tree structure table generating module 52, configured to generate an initial tree structure table based on the initial sql file;
a configuration sql file receiving module 53, configured to receive a configuration sql file for the initial tree structure table; configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table;
an initial tree structure table configuration module 54, configured to configure an initial tree structure table based on the configuration sql file to obtain a tree structure table; wherein the tree structure table comprises a plurality of levels of nodes, each node comprising one or more child nodes.
The embodiment of the invention provides a generating device of a tree structure table, which is used for generating an initial tree structure table based on a received initial sql file; configuring an initial tree structure table based on the received configuration sql file to obtain a tree structure table; wherein configuring the sql file comprises: modifying, adding or deleting node information of one or more nodes in the initial tree structure table; the tree structure table includes a plurality of levels of nodes, each node including one or more child nodes. In the method, the initial sql file and the configured sql file can be directly processed through the database management system to obtain the tree structure table, the operation is simple, the time cost is low, and meanwhile, the method can flexibly modify the data structure of the tree structure table according to different application scenes.
Further, the database management system is in communication connection with the server; the server is in communication connection with the client; the initial sql file receiving module is further configured to: and receiving the initial sql file sent by the server through the database interface program.
Further, the initial sql file is generated by the following method: the client responds to a generation instruction aiming at the initial tree structure table, and generates a first json file based on the table structure information and the data structure information of the initial tree structure table; and the client responds to a saving instruction aiming at the initial tree structure table, and sends the first json file to the server so that the server converts the first json file into an initial sql file.
Further, the database management system is in communication connection with the server; the server is in communication connection with the client; and the initial tree structure table receiving module is used for receiving the configuration sql file sent by the server through the database interface program.
Further, the above configuration sql file is generated by the following method: processing the initial tree structure table into a second json file after receiving a query instruction of the initial tree structure table; sending the second json file to the client so that the client responds to modification operation aiming at the second json file and generates a configuration json file; sending the configuration json file to a server so that the server converts the second json file into a configuration sql file; wherein the modifying operation comprises: and modifying, adding or deleting the information of the corresponding table structure and/or data structure in the second json file.
Further, the tree structure table includes a plurality of types of nodes; wherein, the nodes or sub-nodes with the same type are corresponding to the same dictionary table; the nodes and the child nodes are used for storing the basic data of the corresponding types.
Further, the initial tree structure table generating module is further configured to: executing the initial sql file in a transaction operation mode to generate an initial tree structure table; the initial tree structure table configuration module is further to: executing the configuration sql file in a transaction operation mode; and changing the table structure and/or the data structure of the initial tree structure table to obtain the tree structure table.
The tree structure table generation device provided by the embodiment of the present invention has the same technical features as the tree structure table generation method provided by the above embodiment, so that the same technical problems can be solved, and the same technical effects can be achieved.
The embodiment also provides an electronic device, which comprises a processor and a memory, wherein the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to realize the generation method of the tree structure table.
Referring to fig. 6, the electronic device includes a processor 100 and a memory 101, where the memory 101 stores machine executable instructions capable of being executed by the processor 100, and the processor 100 executes the machine executable instructions to implement the tree structure table generating method.
Further, the electronic device shown in fig. 6 further includes a bus 102 and a communication interface 103, and the processor 100, the communication interface 103, and the memory 101 are connected through the bus 102.
The Memory 101 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 102 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 6, but that does not indicate only one bus or one type of bus.
Processor 100 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 100. The Processor 100 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the foregoing embodiment in combination with the hardware thereof.
The present embodiments also provide a machine-readable storage medium storing machine-executable instructions that, when invoked and executed by a processor, cause the processor to implement the tree structure table generation method described above.
The method and apparatus for generating a tree structure table and the computer program product of the electronic device provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In addition, in the description of the embodiments of the present invention, unless otherwise explicitly specified or limited, the terms "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meaning of the above terms in the present invention can be understood in specific cases for those skilled in the art.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that the following embodiments are merely illustrative of the present invention, and not restrictive, and the scope of the present invention is not limited thereto: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.