Database access method, system and equipment based on ORM framework and medium

By using the ORM framework-based database access method in the nodejs environment, generating model instances and executing SQL statements through the database connection pool, the problem of high complexity in database operations in the existing technology is solved, and more efficient database operation and development experience is achieved .

CN119066099AInactive Publication Date: 2024-12-03成都虚谷伟业科技有限公司
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411207839.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2024-06-26
Filing Date
2024-08-30
Publication Date
2024-12-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the nodejs environment, the existing ORM methods have shortcomings in reducing the complexity of database operations, resulting in developers still facing high complexity and difficulty when operating databases.

Method used

Using the database access method based on the ORM framework, model instances are generated by obtaining input instance parameters and predefined logical models, model instance operation methods are parsed to generate SQL statements, and the database is connected to the database through the database connection pool, SQL statements are executed, and the final result is Convert it into an instance, blocking the specific implementation process of SQL statements.

Benefits of technology

Reduces the complexity of database operations, improves development efficiency and user experience, and makes it easier for developers to operate databases through instances, reducing development difficulty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119066099A_ABST
    Figure CN119066099A_ABST
Patent Text Reader

Abstract

The invention discloses a database access method, system and device based on an ORM framework and a medium, and relates to the technical field of databases, the method comprises the following steps: obtaining an input instance parameter, and generating a corresponding model instance according to the instance parameter and a predefined logic model; based on the ORM framework, analyzing the model instance according to an operation method of the model instance to obtain a corresponding SQL statement; creating a database connection pool according to the database operation code package, and connecting the database through the database connection pool; executing the SQL statement to obtain an execution result; and converting the execution result into a corresponding instance. The method has the effect of reducing the operation complexity of the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of databases, and in particular to a database access method, system, device and medium based on an ORM framework. Background Art

[0002] Object Relational Mapping (ORM, O / RM, or O / R mapping) is a programming technology used to implement data conversion between different types of systems in object-oriented programming languages. In effect, it actually creates a "virtual object database" that can be used in programming languages.

[0003] In the nodejs environment, ORM method is a technology used to simplify database operations. ORM provides a way to operate the database, including methods for operating data, such as relational queries, transaction management, and data validation. These existing ORM methods are widely used in the nodejs environment and can be used for various types of databases, including relational databases (such as MySQL, PostgreSQL) and non-relational databases (such as MongoDB).

[0004] In order to make the database more widely adaptable to the Javascript development ecosystem, it is necessary to develop an ORM method for the node.js environment so that developers can more easily use Javascript to operate the database and reduce the complexity of database operations. Summary of the invention

[0005] In order to reduce the complexity of database operations, the present application provides a database access method, system, device and medium based on the ORM framework.

[0006] In the first aspect, the present application provides a database access method based on the ORM framework, which adopts the following technical solution:

[0007] A database access method based on an ORM framework, characterized by comprising:

[0008] Obtaining input instance parameters, and generating corresponding model instances according to the instance parameters and a predefined logical model;

[0009] Based on the ORM framework, the model instance is parsed according to the operation method of the model instance to obtain a corresponding SQL statement;

[0010] Create a database connection pool according to the database operation code package, and connect to the database through the database connection pool;

[0011] Execute the SQL statement to obtain the execution result;

[0012] The execution result is converted into a corresponding instance.

[0013] By adopting the above technical solution, the input instance parameters are obtained, and the corresponding model instance is generated according to the instance parameters and the pre-defined logical model, and then the model instance is parsed according to the operation method of the model instance to obtain the corresponding SQL statement, and then a database connection pool is created according to the database operation code package in the ORM framework, and the database is connected through the database connection pool, and then the SQL statement is executed to obtain the execution result, and finally the execution result is converted into the corresponding instance. In the above method, the mapping between the model instance and the table in the database is created based on the ORM framework, and the specific implementation process of the SQL statement is shielded, so that the data in the database can be directly operated through the operation method of the instance, reducing the complexity of database operation, reducing the difficulty of development, and improving development efficiency and user experience.

[0014] Optionally, before the step of obtaining the input instance parameters and establishing the corresponding model instance according to the instance parameters and the predefined logical model, the method further includes:

[0015] Obtaining the table structure in the database;

[0016] A predefined logical model is established according to the table structure; the data types defined in the table structure correspond to the data types defined in the logical model.

[0017] By adopting the above technical solution, in order to establish a logical model, the table structure in the database is obtained, and then a predefined logical model is established according to the table structure, and the data type defined in the table structure corresponds to the data type defined in the logical model.

[0018] Optionally, the step of creating a database connection pool according to the database operation code package includes:

[0019] Call the database operation code package and load the database driver;

[0020] Obtain database information, create a driver class based on the database information, and obtain a database connection; the database information includes database IP, port and user name;

[0021] Call the method in the driver class to create a database connection pool.

[0022] By adopting the above technical solution, in order to create a database connection pool, the database operation code package in the ORM framework is called, and the database driver is loaded, and then the database information is obtained, the database information includes the database IP, port and user name, and a driver class is created according to the database information, and then the database connection is obtained, and finally the method in the driver class is called to create a database connection pool.

[0023] Optionally, the step of executing the SQL statement to obtain an execution result includes: the SQL statement is a query statement;

[0024] A query is performed in the database according to the query statement to obtain a corresponding query result.

[0025] By adopting the above technical solution, when it is necessary to query the data in the database, the corresponding query result can be obtained by querying the database according to the query statement.

[0026] Optionally, the step of connecting to the database through the database connection pool includes:

[0027] Obtain a connection request, and determine whether there is an idle connection in the database connection pool according to the connection request, and if so, obtain the idle connection;

[0028] If not, determine whether a new connection can be created in the database connection pool; if so, create the new connection and obtain the new connection.

[0029] By adopting the above technical solution, in order to realize the connection with the database, a connection request is obtained, and it is determined whether there is an idle connection in the database connection pool according to the connection request. If there is an idle connection in the database connection pool, the idle connection is obtained; if there is no idle connection in the database connection pool, it is determined whether a new connection can be created in the database connection pool; if a new connection can be created in the database connection pool, a corresponding new connection is created and the new connection is obtained, thereby realizing the connection with the database.

[0030] Optionally, the step of obtaining a connection request and determining whether there is an idle connection in the database connection pool according to the connection request, and if so, obtaining the idle connection comprises: the database connection pool comprises a used connection pool and at least two idle connection pools;

[0031] Obtaining a connection request, and determining a target idle connection pool according to the connection request and a predefined connection multiplexing logic; the idle connection pool includes a target idle connection pool and a non-target idle connection pool;

[0032] Determine whether there is a first idle connection in the target idle connection pool, if so, obtain the first idle connection, and put the first idle connection into the used connection pool; if not, determine whether there is a second idle connection in the non-target idle connection pool, if so, obtain the second idle connection, and put the second idle connection into the used connection pool.

[0033] By adopting the above technical solution, in order to obtain the idle connection in the database connection pool, a connection request is obtained, and the target idle connection pool is determined according to the connection request and the predefined connection reuse logic, and the idle connection pool includes the target idle connection pool and the non-target idle connection pool. Then, it is determined whether there is a first idle connection in the target idle connection pool. If there is a first idle connection in the target idle connection pool, the first idle connection is obtained and the first idle connection is placed in the used connection pool; if there is no first idle connection in the target idle connection pool, it is determined whether there is a second idle connection in the non-target idle connection pool. If there is a second idle connection in the non-target idle connection pool, the second idle connection is obtained and the second idle connection is placed in the used connection pool.

[0034] Optionally, if not, determining whether a new connection can be created in the database connection pool, and if a new connection can be created in the database connection pool, creating a new connection, and obtaining the new connection comprises:

[0035] If there is no idle connection in the database connection pool, determining whether a first new connection can be created in the target idle connection pool;

[0036] If yes, creating a first new connection in the target free connection pool, acquiring the first new connection, and placing the first new connection in the used connection pool;

[0037] If not, determine whether a second new connection can be created in the non-target idle connection pool; if so, create the second new connection, obtain the second new connection, and put the second new connection into the used connection pool; if not, enter the waiting connection sequence.

[0038] By adopting the above technical solution, when there is no idle connection in the database connection pool, it is determined whether the first new connection can be created in the target idle connection pool. If the first new connection can be created in the target idle connection pool, the first new connection is created in the target idle connection pool, the first new connection is obtained, and the first new connection is placed in the used connection pool; if the first new connection cannot be created in the target idle connection pool, it is determined whether the second new connection can be created in the non-target idle connection pool; if the second new connection can be created in the non-target idle connection pool, the second new connection is created, the second new connection is obtained, and the second new connection is placed in the used connection pool; if the second new connection cannot be created in the non-target idle connection pool, the connection waiting sequence is entered.

[0039] In the second aspect, the present application also provides a database access system based on the ORM framework, which adopts the following technical solution:

[0040] A database access system based on ORM framework, including:

[0041] A model instance generation module, used to obtain input instance parameters and generate a corresponding model instance according to the instance parameters and a predefined logical model;

[0042] An SQL statement generation module is used to parse the model instance according to the operation method of the model instance to obtain a corresponding SQL statement;

[0043] A database connection module, used to create a database connection pool according to the database operation code package in the ORM framework, and connect to the database through the database connection pool;

[0044] An SQL statement execution module is used to execute the SQL statement and obtain the execution result;

[0045] The execution result conversion module is used to convert the execution result into a corresponding instance.

[0046] In a third aspect, the present application also provides a computer device, which adopts the following technical solution:

[0047] A computer device comprises a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method described in the first aspect when executing the computer program.

[0048] In a fourth aspect, the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0049] A computer-readable storage medium stores a computer program that can be loaded by a processor and execute the method described in the first aspect.

[0050] In summary, the present application includes at least the following beneficial technical effects: obtaining input instance parameters, and generating corresponding model instances according to the instance parameters and the predefined logical model, and then parsing the model instance according to the operation method of the model instance to obtain the corresponding SQL statement, and then creating a database connection pool according to the database operation code package in the ORM framework, and connecting to the database through the database connection pool, and then executing the SQL statement to obtain the execution result, and finally converting the execution result into the corresponding instance. In the above method, a mapping between the model instance and the table in the database is created based on the ORM framework, shielding the specific implementation process of the SQL statement, so that the data in the database can be directly operated through the operation method of the instance, reducing the complexity of database operations, and reducing the difficulty of development, improving development efficiency and user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 It is a schematic diagram of the overall process of an embodiment of the present application.

[0052] Figure 2 It is a schematic diagram of the structure of the system of this application.

[0053] Figure 3 It is a flowchart of the design and implementation of the system of the embodiment of the present application.

[0054] Figure 4 It is a structural block diagram of the computer device of the present application. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solutions and advantages of this application more clear, the following Figure 1-4 It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0056] The embodiment of the present application discloses a database access method based on the ORM framework.

[0057] Reference Figure 1 , a database access method based on ORM framework, comprising the following steps:

[0058] Step S11, obtaining input instance parameters, and generating corresponding model instances according to the instance parameters and a predefined logical model.

[0059] It should be noted that the predefined logical model is a class in JavaScript. The data type defined in the class is a mapping relationship with the data type of the table in the database. In the code implementation, the logical model can be used to operate the table data in the database. The mapping relationship between the logical model and the table in the database is shown in the following example. Assume that the creation statement of a table in the database is:

[0060]

[0061]

[0062] According to the structure of the above table, the logical model can be:

[0063]

[0064] Then the mapping between the table TEST in the database and the logical model Obj is realized through the function method TEST=model.define('TEST',Obj).

[0065] It should be further explained that a model instance is an object generated based on instance parameters and a predefined logical model. There is a mapping relationship between the data type in the model instance and the data type in the table in the database. The data in the table is the same as the data in the model instance obtained through a query. Therefore, it can be said that a model instance corresponds to a piece of data in the table.

[0066] Step S12: Based on the ORM framework, the model instance is parsed according to the operation method of the model instance to obtain a corresponding SQL statement.

[0067] It is understandable that, for a model instance, the method of the model instance (ie, a predefined method), such as save() and get(), can be used to operate the model instance to achieve the purpose of operating the table data in the database.

[0068] It should be noted that the methods in the logical model (i.e., the model instance) include database operation methods, which are encapsulations of database SQL statements. Calling database operation methods for operation is to convert instance parameters into SQL statements that can be executed by the database and execute them. For example, there is a TEST table in the database, and the fields of the TEST table are a, b, c, and d. Now the data {"a":2,"b":"test2","c":"2024-04-01 12:00:00","d":12.3} needs to be stored in the TEST table. Then, the database operation method TEST.save() of the model needs to be called, and the data {"a":2,"b":"test2","c":"2024-04-01 12:00:00","d":12.3} is used as the instance parameter, and then the SQL statement INSERT INTO TEST VALUES(2,'test2','2024-04-0112:00:00',12.3) is generated.

[0069] Step S13, creating a database connection pool according to the database operation code package, and connecting to the database through the database connection pool.

[0070] It is understandable that after converting the model operation method into SQL statements, you need to use the database interface in the node.js environment to connect to the database and execute SQL; if you create a connection every time you execute an SQL statement, it will affect the data execution performance, so you need to use the database connection pool to manage the created connection, and then obtain the reused connection from the database connection pool when using the connection later.

[0071] Step S14, execute the SQL statement to obtain the execution result.

[0072] Step S15, converting the execution result into a corresponding instance.

[0073] It is understandable that in a JavaScript development environment, the result is converted into a JavaScript object for use in subsequent codes.

[0074] In the above implementation, the input instance parameters are obtained, and the corresponding model instance is generated according to the instance parameters and the predefined logical model, and then the model instance is parsed according to the operation method of the model instance to obtain the corresponding SQL statement, and then a database connection pool is created according to the database operation code package in the ORM framework, and the database is connected through the database connection pool, and then the SQL statement is executed to obtain the execution result, and finally the execution result is converted into the corresponding instance. In the above method, the mapping between the model instance and the table in the database is created based on the ORM framework, and the specific implementation process of the SQL statement is shielded, so that the data in the database can be directly operated through the operation method of the instance, reducing the complexity of database operations, reducing the difficulty of development, and improving development efficiency and user experience.

[0075] As a further implementation of the database access method, before the step of obtaining the input instance parameters and establishing the corresponding model instance according to the instance parameters and the predefined logical model, the following steps are also included:

[0076] Step S21, obtaining the table structure in the database.

[0077] Step S22: establishing a predefined logical model according to the table structure.

[0078] Among them, the data types defined in the table structure correspond to the data types defined in the logical model.

[0079] In the above implementation, in order to establish a logical model, a table structure in a database is obtained, and then a predefined logical model is established according to the table structure, and the data types defined in the table structure correspond to the data types defined in the logical model.

[0080] As a further implementation of the database access method, the step of creating a database connection pool according to the database operation code package includes the following steps:

[0081] Step S31, calling the database operation code package and loading the database driver.

[0082] Step S32, obtaining database information, creating a driver class according to the database information, and obtaining a database connection.

[0083] The database information includes database IP, port and user name.

[0084] Step S33, calling the method in the driver class to create a database connection pool.

[0085] In the above implementation, in order to create a database connection pool, the database operation code package in the ORM framework is called, and the database driver is loaded, and then the database information is obtained, the database information includes the database IP, port and user name, and a driver class is created according to the database information, and then the database connection is obtained, and finally the method in the driver class is called to create a database connection pool.

[0086] As a further implementation of the database access method, the step of executing the SQL statement and obtaining the execution result includes: the SQL statement is a query statement;

[0087] Query the database according to the query statement and obtain the corresponding query results.

[0088] It should be noted that SQL statements also include insert statements, delete statements, and modify statements. Insert statements can be used to add data to the database, delete statements can be used to delete data in the database, and modify statements can be used to modify data in the database.

[0089] In the above implementation, when it is necessary to query the data in the database, the corresponding query result can be obtained by querying the database according to the query statement.

[0090] As a further implementation of the database access method, the step of connecting to the database through the database connection pool includes the following steps:

[0091] Get the connection request, and determine whether there is an idle connection in the database connection pool based on the connection request. If so, get the idle connection;

[0092] If not, determine whether a new connection can be created in the database connection pool; if so, create a new connection and obtain the new connection.

[0093] Specifically, a connection request is obtained, and according to the connection request, whether there is an idle connection in the database connection pool is determined; if there is an idle connection in the database connection pool, the idle connection is obtained; if there is no idle connection in the database connection pool, it is determined whether a new connection can be created in the database connection pool; if a new connection can be created in the database connection pool, a corresponding new connection is created and the new connection is obtained.

[0094] In the above implementation, in order to achieve connection with the database, a connection request is obtained, and it is determined whether there is an idle connection in the database connection pool according to the connection request. If there is an idle connection in the database connection pool, the idle connection is obtained; if there is no idle connection in the database connection pool, it is determined whether a new connection can be created in the database connection pool; if a new connection can be created in the database connection pool, a corresponding new connection is created and the new connection is obtained, thereby achieving connection with the database.

[0095] As a further implementation method of the database access method, a connection request is obtained, and according to the connection request, it is determined whether there is an idle connection in the database connection pool, and if so, the step of obtaining the idle connection includes the following steps: the database connection pool includes a used connection pool and at least two idle connection pools;

[0096] Step S61, obtaining a connection request, and determining a target idle connection pool according to the connection request and a predefined connection multiplexing logic.

[0097] The idle connection pool includes a target idle connection pool and a non-target idle connection pool.

[0098] It can be understood that the idle connection pool includes a target idle connection pool and a plurality of non-target idle connection pools.

[0099] Step S62, determine whether there is a first idle connection in the target idle connection pool, if so, obtain the first idle connection and put the first idle connection into the used connection pool; if not, determine whether there is a second idle connection in the non-target idle connection pool, if so, obtain the second idle connection and put the second idle connection into the used connection pool.

[0100] Specifically, it is determined whether there is a first idle connection in the target idle connection pool. If there is a first idle connection in the target idle connection pool, the first idle connection is obtained and placed in the used connection pool. If there is no first idle connection in the target idle connection pool, it is determined whether there is a second idle connection in the non-target idle connection pool. If there is a second idle connection in the non-target idle connection pool, the second idle connection is obtained and placed in the used connection pool.

[0101] It can be understood that, to determine whether there is a second idle connection in the non-target idle connection pool, that is, to determine whether there is a second idle connection in the non-target idle connection pool in sequence according to a predefined order, when it is determined that there is a second idle connection in a non-target idle connection pool, the determination is stopped and the second idle connection in the non-target idle connection pool is obtained.

[0102] In the above implementation, in order to obtain an idle connection in the database connection pool, a connection request is obtained, and a target idle connection pool is determined according to the connection request and a predefined connection reuse logic, wherein the idle connection pool includes a target idle connection pool and a non-target idle connection pool. Then, it is determined whether there is a first idle connection in the target idle connection pool. If there is a first idle connection in the target idle connection pool, the first idle connection is obtained and placed in the used connection pool; if there is no first idle connection in the target idle connection pool, it is determined whether there is a second idle connection in the non-target idle connection pool. If there is a second idle connection in the non-target idle connection pool, the second idle connection is obtained and placed in the used connection pool.

[0103] As a further implementation method of the database access method, if not, determining whether a new connection can be created in the database connection pool, and if a new connection can be created in the database connection pool, creating a new connection, and obtaining the new connection step include:

[0104] If there is no idle connection in the database connection pool, determine whether the first new connection can be created in the target idle connection pool;

[0105] If yes, create a first new connection in the target free connection pool, obtain the first new connection, and put the first new connection into the used connection pool;

[0106] If not, determine whether a second new connection can be created in the non-target idle connection pool; if so, create a second new connection, obtain the second new connection, and put the second new connection into the used connection pool; if not, enter the waiting connection sequence.

[0107] Specifically, if there are no idle connections in the target idle connection pool and the non-target idle connection pool, it is determined whether the first new connection can be created in the target idle connection pool. If the first new connection can be created in the target idle connection pool, the first new connection is created in the target idle connection pool, the first new connection is obtained, and the first new connection is placed in the used connection pool; if the first new connection cannot be created in the target idle connection pool, it is determined whether the second new connection can be created in the non-target idle connection pool; if the second new connection can be created in the non-target idle connection pool, the second new connection is created, the second new connection is obtained, and the second new connection is placed in the used connection pool; if the second new connection cannot be created in the non-target idle connection pool, the connection waiting sequence is entered.

[0108] In the above implementation, when there is no idle connection in the database connection pool, it is determined whether the first new connection can be created in the target idle connection pool. If the first new connection can be created in the target idle connection pool, the first new connection is created in the target idle connection pool, the first new connection is obtained, and the first new connection is placed in the used connection pool; if the first new connection cannot be created in the target idle connection pool, it is determined whether the second new connection can be created in the non-target idle connection pool; if the second new connection can be created in the non-target idle connection pool, the second new connection is created, the second new connection is obtained, and the second new connection is placed in the used connection pool; if the second new connection cannot be created in the non-target idle connection pool, the waiting connection sequence is entered.

[0109] The embodiment of the present application also discloses a database access system based on the ORM framework.

[0110] refer to Figure 2 , a database access system based on ORM framework, including:

[0111] A model instance generation module is used to obtain input instance parameters and generate corresponding model instances according to the instance parameters and a predefined logical model;

[0112] SQL statement generation module, used to parse the model instance according to the operation method of the model instance to obtain the corresponding SQL statement;

[0113] The database connection module is used to create a database connection pool according to the database operation code package in the ORM framework, and connect to the database through the database connection pool;

[0114] SQL statement execution module, used to execute SQL statements and obtain execution results;

[0115] The execution result conversion module is used to convert the execution result into the corresponding instance.

[0116] refer to Figure 3 In the process of designing and implementing the database access system based on the ORM framework of this embodiment, the logical model is first defined, and then the input instance parameters are obtained, and the corresponding model instance is generated according to the instance parameters and the pre-defined logical model. Then the designer can operate the model instance according to the method in the pre-defined logical model, and then generate SQL statements by parsing the model instance; after establishing a connection with the database, the data in the database is operated by executing SQL statements, and after completing the corresponding operation, the returned result set is obtained.

[0117] The ORM framework-based database access system of the present invention can implement any one of the ORM framework-based database access methods, and the specific working process of the ORM framework-based database access system of the present invention can refer to the corresponding process in the above-mentioned ORM framework-based database access method.

[0118] The embodiment of the present application also discloses a computer device.

[0119] refer to Figure 4 A computer device includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, any of the above-mentioned database access methods based on the ORM framework is implemented.

[0120] The embodiment of the present application also discloses a computer-readable storage medium.

[0121] A computer-readable storage medium stores a computer program that can be loaded by a processor and execute any one of the above-mentioned database access methods based on the ORM framework.

[0122] Among them, computer-readable storage media can be any tangible medium that contains or stores a program, which can be used by or in conjunction with an instruction execution system, apparatus or device; the program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0123] The above are all preferred embodiments of the present application, and are not intended to limit the protection scope of the present application. Any feature disclosed in this specification (including the abstract and drawings), unless otherwise stated, can be replaced by other equivalent or alternative features with similar purposes. That is, unless otherwise stated, each feature is only an example of a series of equivalent or similar features.

Claims

1. A database access method based on ORM framework, characterized in that: include: Obtaining input instance parameters, and generating corresponding model instances according to the instance parameters and a predefined logical model; Based on the ORM framework, the model instance is parsed according to the operation method of the model instance to obtain a corresponding SQL statement; Create a database connection pool according to the database operation code package, and connect to the database through the database connection pool; Execute the SQL statement to obtain the execution result; The execution result is converted into a corresponding instance.

2. According to a database access method based on ORM framework according to claim 1, it is characterized in that: Before the step of obtaining the input instance parameters and establishing the corresponding model instance according to the instance parameters and the predefined logical model, the method further includes: Obtaining a table structure in the database; A predefined logical model is established according to the table structure; the data types defined in the table structure correspond to the data types defined in the logical model.

3. The database access method based on ORM framework according to claim 1, characterized in that: The step of creating a database connection pool according to the database operation code package includes: Call the database operation code package and load the database driver; Obtain database information, create a driver class based on the database information, and obtain a database connection; the database information includes database IP, port and user name; Call the method in the driver class to create a database connection pool.

4. The database access method based on the ORM framework according to claim 1, characterized in that: The step of executing the SQL statement to obtain the execution result includes: the SQL statement is a query statement; A query is performed in the database according to the query statement to obtain a corresponding query result.

5. The database access method based on ORM framework according to claim 1, characterized in that: The step of connecting to the database through the database connection pool includes: Obtain a connection request, and determine whether there is an idle connection in the database connection pool according to the connection request, and if so, obtain the idle connection; If not, determine whether a new connection can be created in the database connection pool; if so, create the new connection and obtain the new connection.

6. The database access method based on ORM framework according to claim 1, characterized in that: The step of obtaining a connection request and determining whether there is an idle connection in the database connection pool according to the connection request, and if so, obtaining the idle connection comprises: the database connection pool comprises a used connection pool and at least two idle connection pools; Obtaining a connection request, and determining a target idle connection pool according to the connection request and a predefined connection multiplexing logic; the idle connection pool includes a target idle connection pool and a non-target idle connection pool; Determine whether there is a first idle connection in the target idle connection pool, if so, obtain the first idle connection, and put the first idle connection into the used connection pool; if not, determine whether there is a second idle connection in the non-target idle connection pool, if so, obtain the second idle connection, and put the second idle connection into the used connection pool.

7. The database access method based on ORM framework according to claim 6 is characterized in that: If not, determining whether a new connection can be created in the database connection pool, and if a new connection can be created in the database connection pool, creating a new connection, and obtaining the new connection comprises: If there is no idle connection in the database connection pool, determining whether a first new connection can be created in the target idle connection pool; If yes, creating a first new connection in the target free connection pool, acquiring the first new connection, and placing the first new connection in the used connection pool; If not, determine whether a second new connection can be created in the non-target idle connection pool; if so, create the second new connection, obtain the second new connection, and put the second new connection into the used connection pool; if not, enter the waiting connection sequence.

8. A database access system based on ORM framework, characterized in that: include: A model instance generation module, used to obtain input instance parameters and generate a corresponding model instance according to the instance parameters and a predefined logical model; An SQL statement generation module is used to parse the model instance according to the operation method of the model instance to obtain a corresponding SQL statement; A database connection module, used to create a database connection pool according to the database operation code package in the ORM framework, and connect to the database through the database connection pool; An SQL statement execution module is used to execute the SQL statement and obtain the execution result; The execution result conversion module is used to convert the execution result into a corresponding instance.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Connection multiplexing method and connection multiplexing device for database management system

    CN103810203A

  • Connection method, device and system of multivariate dynamic connection pool

    CN112732441A

  • GraphQL-based data processing method and device, service terminal and storage medium

    CN112783958A

  • Data interaction processing method and device, equipment and medium

    CN116860774A