Database adaptation method, device and equipment based on Django framework

CN122985755APending Publication Date: 2026-10-27GRG INTELLIGENT TECH SOLUTION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611155502.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0002]GBase8s数据库与MySQL、PostgreSQL等主流数据库在字段类型、SQL语法、连接交互等方面存在显著原生差异,Django框架无法原生兼容

Benefits of technology

[0010]第六方面,本申请提供了一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上述第一方面所述的基于Django框架的数据库适配方法。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122985755A_ABST
    Figure CN122985755A_ABST
Patent Text Reader

Abstract

The application discloses a database adaptation method and device based on a Django framework and equipment, and belongs to the technical field of databases. The method comprises the following steps: establishing a database connection between a service and a GBase8s database according to connection parameters of the GBase8s database, wherein the service is built based on the Django framework; responding to a database request initiated through the Django framework, and verifying the validity of the database connection; in the case that the validity verification is passed, performing corresponding adaptation processing according to the type of the database request, generating target interaction content adapted to the GBase8s database; performing interaction according to the target interaction content and the GBase8s database, and performing corresponding adaptation processing on the interaction result to obtain a database request result adapted to the Django framework. The application improves the development efficiency of connecting the GBase8s database based on the Django framework.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of database technology, and in particular relates to a database adaptation method, apparatus and device based on the Django framework. Background Technology

[0002] GBase8s databases differ significantly from mainstream databases such as MySQL and PostgreSQL in terms of field types, SQL syntax, and connection interactions, making them inherently incompatible with the Django framework. Furthermore, existing adaptation solutions often only convert surface-level SQL statements and lack deep integration with Django's core ecosystem, such as migrations and introspection. This prevents differentiated adaptation based on different database requests, often requiring additional code modifications at the business layer and failing to meet the actual needs of Django-based projects integrating with GBase8s databases. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the related art. To this end, this application proposes a database adaptation method, apparatus, and device based on the Django framework, which improves the development efficiency of connecting to the GBase8s database based on the Django framework.

[0004] Firstly, this application provides a database adaptation method based on the Django framework, which includes: Based on the connection parameters of the GBase8s database, a database connection is established between the service and the GBase8s database, wherein the service is built based on the Django framework; In response to database requests initiated through the Django framework, the validity of the database connection is verified. If the validity verification passes, the corresponding adaptation process is performed according to the type of the database request to generate target interactive content adapted to the GBase8s database. The interaction is performed with the GBase8s database based on the target interaction content, and the corresponding adaptation processing is performed on the interaction result to obtain the database request result adapted to the Django framework.

[0005] In the above technical solution, after establishing a database connection between the service and the GBase8s database, invalid connections are identified in advance through connection validity verification to avoid request execution failures due to connection anomalies. If the validity verification passes, differentiated adaptation is implemented according to the database request type. Adaptation logic can be used for database requests in different scenarios, avoiding incompatibility issues or redundancy caused by general adaptation. This aligns with the native operating mechanism of each functional module of the Django framework, achieving deep integration with the framework ecosystem. Furthermore, corresponding adaptation processing is performed on the interaction results, achieving fully automated adaptation from request sending to result return, solving the problem that the Django framework cannot natively support the GBase8 database. Moreover, the business layer is unaware and non-intrusive. Compared to the simple implementation of table-level character replacement in SQL statements, this approach, aligning with the native operating mechanism of each function of the Django framework, enables efficient interaction between the Django framework and the GBase8s database, improving the development efficiency of connecting the Django framework to the GBase8s database.

[0006] Secondly, this application provides a database adaptation device based on the Django framework, the device comprising: The connection module is used to establish a database connection between the service and the GBase8s database based on the connection parameters of the GBase8s database. The service is built based on the Django framework. The verification module is used to respond to database requests initiated through the Django framework and verify the validity of the database connection. The adaptation module is used to perform corresponding adaptation processing according to the type of the database request when the validity verification passes, and generate target interactive content adapted to the GBase8s database. The interaction module is used to interact with the GBase8s database according to the target interaction content, and to perform corresponding adaptation processing on the interaction results to obtain the database request results adapted to the Django framework.

[0007] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the database adaptation method based on the Django framework as described in the first aspect above.

[0008] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the database adaptation method based on the Django framework as described in the first aspect above.

[0009] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the database adaptation method based on the Django framework as described in the first aspect.

[0010] Sixthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the database adaptation method based on the Django framework as described in the first aspect above.

[0011] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0012] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating a database adaptation method based on the Django framework provided in some embodiments of this application; Figure 2 These are schematic diagrams of adapters provided in some embodiments of this application; Figure 3 This is a schematic diagram of the structure of a database adaptation device based on the Django framework provided in some embodiments of this application; Figure 4 These are schematic diagrams of the structure of electronic devices provided in some embodiments of this application. Detailed Implementation

[0013] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments that can be directly obtained based on the embodiments of this application are within the scope of protection of this application.

[0014] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0015] GBase8s database has several inherent incompatibilities with mainstream open-source databases (such as MySQL and PostgreSQL). Specifically, there are differences in field type systems; for example, the field types in GBase8s database cannot directly correspond to the field types natively mapped to MySQL and PostgreSQL in the Django framework. There are also differences in Structured Query Language (SQL) syntax; for instance, GBase8s database is incompatible with standard SQL syntax in areas such as default value syntax, null value identification, and JavaScript Object Notation (JSON) field reading and writing syntax. Furthermore, command-line interaction and connection configuration specifications also differ from mainstream databases, making compatibility impossible to achieve through simple surface-level adaptation.

[0016] Django's Object-Relational Mapping (ORM) feature maps object models to relational databases, effectively simplifying database operation code and improving development efficiency. However, in related technologies, database backends built on the Django framework typically cannot directly connect to and manipulate GBase8s databases through its ORM functionality. Furthermore, many related adaptation solutions adopt a generalized design, limiting adaptation within the Django framework to simple conversions of table-level SQL statements, failing to achieve deep integration with the Django ecosystem and thus unable to meet the actual needs of projects for efficient and stable operation of the GBase8s database. Therefore, a dedicated adaptation solution is required for GBase8s databases to achieve full compatibility with the Django framework.

[0017] This application solves or at least partially solves the problems mentioned above. The database adaptation method, apparatus, and device based on the Django framework provided in this application will be described in detail below with reference to the accompanying drawings and specific embodiments and application scenarios.

[0018] Among them, the database adaptation method based on the Django framework can be applied to the terminal, specifically executed by the hardware or software in the terminal.

[0019] The database adaptation method based on the Django framework provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the database adaptation method based on the Django framework. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The following uses an electronic device as the execution subject to illustrate the database adaptation method based on the Django framework provided in this application embodiment.

[0020] Figure 1 This is a flowchart illustrating a database adaptation method based on the Django framework provided in some embodiments of this application. Figure 1 As shown, the database adaptation method based on the Django framework includes steps 110, 120, 130, and 140.

[0021] Step 110: Establish a database connection between the service and the GBase8s database according to the connection parameters of the GBase8s database. The service is built based on the Django framework.

[0022] Connection parameters include configuration information used to establish a database connection, such as address, port, username, password, database instance, and character set. A database connection refers to the communication link established between the service and the GBase8s database based on the connection parameters, which can be used to issue commands, transmit data, and return results.

[0023] For example, the connection parameters such as the IP address, port, username, password, and database name of the GBase8s database can be read from the configuration file, and a communication connection between the service and the database can be created through the dedicated GBase8s driver.

[0024] Step 120: Respond to the database request initiated through the Django framework and verify the validity of the database connection.

[0025] A database request is a database operation request initiated by the service through the Django framework, which can include data manipulation, structure migration, structure introspection, command-line interaction, etc. In this embodiment, the database connection validity is verified in response to the database request initiated by the Django framework. This can be done by executing lightweight statements to check whether the database connection is properly established before the database request is initiated; or by checking the connection status identifier, session status, etc. returned by the driver to determine whether the current database connection is in a valid state.

[0026] By validating the database connection, we can effectively avoid request execution failures due to connection errors and ensure that subsequent adaptation processing and database interactions are based on a reliable connection.

[0027] Step 130: If the validity verification passes, perform the corresponding adaptation processing according to the type of the database request to generate target interactive content adapted to the GBase8s database.

[0028] Adaptation processing refers to converting requests initiated through the Django framework into GBase8s-recognizable content based on GBase8s database requirements, such as syntax rules, field types, and interaction specifications. The target interaction content, after adaptation processing, consists of SQL statements or command-line configuration parameters that can be executed by the GBase8s database.

[0029] Understandably, by dividing database requests by type, different adaptation strategies and processing logics can be matched for database requests from different business scenarios and different call entry points. For example, layered adaptation can be performed from multiple dimensions such as field type mapping, syntax rule adaptation, and data query logic to achieve deep integration of the adaptation mechanism with the Django framework, rather than isolated intermediate layer format conversion.

[0030] For example, in some implementations, database requests initiated by the Django framework are pre-classified according to the business scenario and functional attributes to which the request belongs; at runtime, the current request type is identified, and the adaptation logic matching the type is called to output the target interactive content that conforms to the GBase8s database operation specification.

[0031] In some embodiments, different rule sets can also be associated and bound with different database request types; when a database request triggers the adaptation process, the corresponding rule set is retrieved according to the request type, and the automatic adaptation and generation of fields, syntax, format, interaction parameters, etc. are automatically completed, which improves the limitations of a single general SQL conversion logic.

[0032] Differentiated adaptation based on database request type allows for the use of adaptation logic for database requests in different scenarios, avoiding incompatibility issues or redundancy caused by general adaptation. Unlike related technologies that simply replace table characters in SQL statements, this application's embodiment designs adaptation logic based on request type layering, which can fit the native operating mechanism of each functional module of the Django framework and achieve deep integration with the framework ecosystem.

[0033] Furthermore, by using request type as the dimension for dividing the adaptation logic, when a new database request scenario or database feature is added, only the corresponding type of adaptation strategy needs to be added; the adaptation processing based on request type can be embedded into the original request initiation and execution process of the Django framework, and the business side can adapt to the GBase8s database without modifying the code.

[0034] Step 140: Execute interaction with the GBase8s database based on the target interaction content, and perform corresponding adaptation processing on the interaction result to obtain the database request result adapted to the Django framework.

[0035] Understandably, the interaction results returned after interacting with the GBase8s database need to undergo reverse adaptation before they can be recognized by the Django framework. For example, after receiving the raw interaction results returned by the database, the original results can be processed by combining preset field reverse mapping rules and Django framework data format specifications to perform type conversion, format standardization, and other processing, so that the interaction results can be directly recognized and used by the Django framework.

[0036] In some embodiments, based on the type of database request, corresponding adaptation processing is performed on the target interaction content corresponding to the database request to perform differentiated reverse adaptation: for example, the result of a data operation request is converted into a model object that the Django framework can directly parse; the result of a structure introspection request is converted into a structured data format that the Django framework can recognize, etc.

[0037] The database adaptation method based on the Django framework provided in this application, after establishing a database connection between the service and the GBase8s database, identifies invalid connections in advance through connection validity verification to avoid request execution failure due to connection anomalies. If the validity verification passes, differentiated adaptation is implemented according to the database request type. Adaptation logic can be used for database requests in different scenarios, avoiding incompatibility issues or redundancy caused by general adaptation. This method aligns with the native operating mechanism of each functional module of the Django framework, achieving deep integration with the framework ecosystem. Furthermore, corresponding adaptation processing is performed on the interaction results, achieving fully automated adaptation from request sending to result return, solving the problem that the Django framework cannot natively support the GBase8 database. Moreover, it is seamless and non-intrusive to the business layer. Compared to the simple implementation of table-level character replacement in SQL statements, this method, aligned with the native operating mechanism of each function of the Django framework, enables efficient interaction between the Django framework and the GBase8s database, improving the development efficiency of connecting the Django framework to the GBase8s database.

[0038] In some embodiments, this Django framework-based database adaptation method is applied to the Django-GBase8s database adapter. Figure 2 These are schematic diagrams of adapters provided in some embodiments of this application. For example... Figure 2 As shown, the Django-GBase8s database adapter is set between the Django framework's ORM layer and the GBase8s database, acting as an intermediate adaptation layer to achieve bidirectional adaptation and transparent interaction between the Django framework and the GBase8s database. Taking a data operation request as an example: The Django application layer initiates database requests by manipulating model objects using Python (such as CRUD operations). These requests are then passed to the Django ORM layer. The ORM layer translates the model operations into standard SQL statements and passes them down to the Django-GBase8s adapter. The adapter receives standard SQL statements from the ORM layer, performs type conversion and compatibility processing through preset field mapping rules and syntax adaptation logic, converts the standard SQL statements into GBase SQL statements that can be directly executed by the GBase8s database, and then passes them down to the GBase8s database for execution. The GBase8s database receives the adapted SQL statements, performs data operations (CRUD operations), and returns the execution results to the Django-GBase8s adapter. The adapter receives the execution results returned by the GBase8s database, adapts the results to make their format and type compatible with Django ORM, and then passes the adapted results up to the Django ORM layer. The Django ORM layer converts the results returned by the adapter into Python objects, which are then fed back to the Django application layer for service use.

[0039] This Django-GBase8s adapter enables end-to-end adaptation from the Django application layer to the GBase8s database, achieving compatibility between the Django framework and the GBase8s database without requiring modifications to either the Django framework or the GBase8s database.

[0040] In some embodiments of this application, the type of the database request includes at least one of the following: data operation request, database migration request, database introspection request, and command-line interaction request. The step of performing corresponding adaptation processing based on the type of the database request to generate target interactive content adapted to the GBase8s database includes at least one of the following: If the database request is a data operation request, the SQL statement corresponding to the data operation request is converted into an execution SQL statement adapted to the GBase8s database according to the preset field mapping rules and the syntax rules of the GBase8s database. If the database request is a database migration request, the SQL statement corresponding to the database migration request is converted into an execution SQL statement adapted to the GBase8s database according to the preset structure change SQL template. If the database request is a database introspection request, generate a structure query SQL statement adapted to the GBase8s database according to the field mapping rules; If the database request is a command-line interactive request, generate client startup configuration parameters adapted to the GBase8s database.

[0041] Data manipulation requests refer to requests initiated through the Django framework to perform CRUD operations on data in the GBase8s database, typically generating basic SQL statements (such as SELECT, INSERT, UPDATE, DELETE, etc.).

[0042] Field mapping rules include mapping rules from Django framework field types to database field types, as well as bidirectional mapping rules from database field types to Django framework field types. GBase8s database syntax rules refer to GBase8s's own SQL syntax specifications, including field default value syntax, null value identification, JSON field reading and writing, table structure modification, and other unique syntax, some of which differ from mainstream data syntax.

[0043] In some implementations, if the database request is a data operation request, after intercepting the native SQL statement generated by the Django framework, the native Django field types in the statement are first mapped to GBase8s-compatible field types using preset field mapping rules. Then, combined with GBase8s syntax rules, incompatible parts of the SQL statement, such as default values, null value identifiers, and JSON field read / write syntax, are corrected to generate a directly executable SQL statement. By resolving the incompatibility issue between GBase8s database and Django framework field types and correcting syntax format through field mapping rules, dual-rule adaptation ensures that all types of data operation requests (CRUD operations) initiated by the Django ORM can be stably executed in GBase8s.

[0044] A database migration request is a request initiated through the Django migration module (migrations) to create, modify, or delete (such as adding fields, modifying field types, or deleting tables) the table structure of a GBase8s database, and is used to implement changes to the table structure of a GBase8s database.

[0045] The structure change SQL template refers to a standardized SQL template preset for scenarios involving changes to the structure of GBase8s database tables (such as adding fields or modifying field types). It is designed in conjunction with the syntax features of GBase8s structure changes and can be used to convert the SQL statements corresponding to Django migration requests into GBase8s executable format.

[0046] In some implementations, after intercepting the native structure change SQL generated by the Django migration module, the corresponding template is matched, incompatible syntax and field types are replaced, and execution SQL adapted to GBase8s is generated. Designing templates specifically for GBase8s' unique structure specifications effectively avoids the inability of existing general adaptation solutions to handle complex structure changes. Furthermore, template-based adaptation reduces redundant manual SQL rewriting and ensures that the structure change logic conforms to the GBase8s specification, preventing issues such as table structure anomalies and data loss during migration.

[0047] A database introspection request is a request initiated through the Django introspection module to query GBase8s database metadata (such as table structure, field types, and index information), used to obtain the structured data of the GBase8s database.

[0048] For example, based on field mapping rules and the structure of GBase8s system tables (tables storing metadata), targeted structure query SQL statements can be generated to query metadata such as table structure, field types, and index information. Structure query SQL statements are SQL statements designed for GBase8s system tables and used to query database metadata.

[0049] Understandably, compared to general solutions in related technologies that cannot adapt to the unique system table structure of GBase8s and can only achieve shallow queries, this embodiment achieves accurate metadata querying and adaptation through field mapping rules and dedicated query SQL. By reverse-adapting through field mapping rules, the metadata format of GBase8s is made consistent with the expected format of the Django introspection module, ensuring that the Django framework can correctly parse and use metadata (such as automatically generating model classes), guaranteeing the accuracy and compatibility of introspection results.

[0050] Command-line interactive requests refer to requests initiated through the Django framework that invoke the native GBase8s command-line tools for database operation and maintenance (such as batch script execution and database configuration adjustments). These requests generate client startup parameters that conform to the GBase8s specification. Client startup configuration parameters are those that conform to the GBase8s native command-line client startup specification and may include the database instance, port, username, password, and interaction mode. These parameters are used to start the client and establish a command-line interactive connection with GBase8s.

[0051] The database adaptation method based on the Django framework provided in this application has designed differentiated adaptation processing logic for four types of database requests (data operation, database migration, database introspection, and command-line interaction) according to the functional characteristics and adaptation requirements of each type of request. Compared with the generalized adaptation methods of related technologies and surface SQL rewriting, this method combines preset field mapping rules, GBase8s syntax rules, and structure change SQL templates to perform precise adaptation for each type of request, generate target interactive content adapted to the GBase8s database, and achieve deep integration with the Django ecosystem, rather than isolated intermediate layer conversion. This fills the adaptation gap of existing adaptation solutions in various adaptation scenarios and ensures that all types of requests initiated through the Django framework can be executed stably and efficiently in GBase8s.

[0052] In some embodiments of this application, the step of converting the SQL statement corresponding to the data operation request into an executable SQL statement adapted to the GBase8s database according to preset field mapping rules and the syntax rules of the GBase8s database includes: Determine the default values ​​for the fields in the SQL statement and the fields of type JSON; Based on the syntax rules of the GBase8s database, the default values ​​of the fields are adapted and determined. The default values ​​of fields that are determined to be incompatible with the GBase8s database through the adaptation judgment will be converted into null value identifiers that are compatible with the GBase8s database. According to the syntax rules of the database, the JSON type field data in the SQL statement is serialized to make the format of the JSON type field data adapt to the GBase8s database.

[0053] Default field values ​​refer to the default data specified when creating a table or adding a new field. The database automatically fills in the default values ​​when no value is explicitly passed in. Different databases have different requirements for the format and syntax of default values. JSON type fields are used to store structured JavaScript Object Notation (JSON) formatted data. The Django framework and GBase8s database have incompatible requirements for writing, reading, and serializing JSON fields.

[0054] For example, it could parse the SQL statements generated by Django, extract the corresponding default values, and identify and locate fields of type JSON; or it could use field type annotations and syntax parsers to extract fields with default values ​​and JSON fields from data operation requests; providing processing objects for subsequent default value adaptation and JSON field processing helps improve adaptation accuracy.

[0055] In some embodiments, the default values ​​of the fields are adapted according to the syntax rules of the GBase8s database. This includes: validating the default values ​​of the fields according to the syntax and format specifications of the GBase8s database; determining whether the default values ​​can be directly recognized and executed by GBase8s; and obtaining an adaptation judgment result to characterize whether the fields are adapted. Default values ​​that do not conform to the GBase8s specification are removed or replaced with standard GBase8s null values ​​to ensure that the fields can be created and written normally.

[0056] Serialization is the process of converting an object's state into a storable or transmittable form. For example, it can involve escaping, formatting, and structurally organizing JSON data according to the GBase8s database's JSON field storage specifications to generate a JSON string that conforms to the database's requirements. This can resolve incompatibility issues between the Django framework and the GBase8s database regarding JSON field formats, ensuring that JSON data can be written, read, and parsed correctly, and improving the data integrity of executed SQL statements.

[0057] In some embodiments, the method further includes: When data is written to the GBase8s database, JSON type fields are serialized to convert them into a format recognizable by the GBase8s database. Conversely, when data is read from the GBase8s database, JSON type fields are deserialized to convert them into a format recognizable by the Django framework. Through this bidirectional adaptation process, compatible interaction of JSON format data between the Django framework and the target database is achieved.

[0058] The database adaptation method based on the Django framework provided in this application addresses incompatible default values ​​and JSON type fields in GBase8s databases. It converts the incompatible default values ​​into nullable identifiers compatible with GBase8s databases and performs serialization processing on JSON type field data in SQL statements to ensure the format of the JSON type field data is adapted to the GBase8s database. This achieves deep adaptation rather than superficial SQL conversion, converting SQL statements generated by the Django framework into executable SQL statements that fully conform to the GBase8s specification. Adaptation is completed at the level of data format, syntax specifications, and storage rules, rather than simple character replacement. This makes the adaptation between the Django framework and the GBase8s database more stable and reliable, avoiding execution failures caused by invalid default values ​​or incorrect JSON format data, and improving the success rate of SQL statement execution.

[0059] In some embodiments of this application, the field mapping rules are also used for: When the SQL statement includes a model field type for storing short strings, the model field type is mapped to the variable-length string field type of the GBase8s database.

[0060] The short string model field type (CharField) refers to the model field type in the Django framework used to store short text or short character content. The variable-length string field type refers to the VARCHAR type in the GBase8s database; it is a variable-length character type that automatically allocates space based on the actual content being stored.

[0061] In some implementations, the binding relationship between Django short string model field types and GBase8s variable-length string field types is pre-configured in the field mapping rules. During SQL statement parsing, the short string model field identifier within the statement is identified, matched against the pre-defined mapping relationship, and automatically replaced with the corresponding GBase8s variable-length string field type identifier. This eliminates the type difference between Django framework short string model fields and GBase8s database variable-length string fields, avoiding problems such as table creation failure, data insertion anomalies, and field validation errors caused by field type mismatches. The database adaptation method based on the Django framework provided in this application addresses the issue of incompatibility between CharField in the Django framework and fields in the GBase8s database. This method uses preset field mapping rules to map short string Django model field types appearing in SQL statements to the corresponding variable-length string field types in the GBase8s database. Furthermore, since the GBase8s database has limited support for the CHAR type, mapping to the variable-length string field type (VARCHAR) can ensure that SQL statements can be executed normally in the GBase8s database, compared to the storage waste and syntax incompatibility issues that may result from forcibly using CHAR fields as the mapping type. Using VARCHAR, which is natively supported by GBase8s, helps to improve storage performance and runtime performance.

[0062] In some embodiments of this application, the step of interacting with the GBase8s database based on the target interaction content and performing corresponding adaptation processing on the interaction result to obtain a database request result adapted to the Django framework includes: If the database request is a database introspection request, execute the structure query SQL statement to query the system tables of the GBase8s database and obtain the structure data of the GBase8s database. The structured data is adapted based on the field mapping rules to generate model structured data adapted to the Django framework.

[0063] Understandably, database introspection requests are query requests initiated by services built on the Django framework to obtain the metadata structure of database tables, fields, types, etc. System tables are dedicated system tables of the GBase8s database itself used to store metadata (table names, field names, field types, lengths, constraints, etc.).

[0064] In some embodiments, a preset structure query SQL statement can be executed based on the GBase8s proprietary system table structure to read raw metadata such as table name, field name, field type, length, and whether it is empty from the system table; alternatively, the system table query statement can be executed through the driver corresponding to the GBase8s database to obtain the database's native structure data and return it to the adaptation layer.

[0065] The original structured data is obtained, and then reverse adaptation is performed using field mapping rules to convert the native GBase8s structured data into model structured data that can be directly used by the Django framework. For example, it can be reverse mapped to model field types that the Django framework can recognize through field mapping rules, and the field length, constraints, default values, null value identifiers and other information in the structured data are formatted and converted into standard structured data that can be directly parsed by the Django introspection module.

[0066] The database adaptation method based on the Django framework provided in this application, when the request is for database introspection, obtains the original structure data by executing a structure query SQL to query the GBase8s system tables, and then uses field mapping rules for reverse adaptation to convert the native GBase8s structure data into model structure data that can be directly used by the Django framework. It supports the Django framework to automatically identify the GBase8s database table structure and automatically generate the model structure, and can fully reuse the framework's native capabilities without modifying the framework code. Unlike surface data conversion, it realizes the adaptation of the Django framework's introspection function to the GBase8s database.

[0067] In some embodiments of this application, the step of interacting with the GBase8s database based on the target interaction content and performing corresponding adaptation processing on the interaction result to obtain a database request result adapted to the Django framework includes: If the database request is a command-line interaction request, start the database's native command-line tool based on the client startup configuration parameters, and establish a command-line interaction connection between the service and the database; Based on the command-line execution rules of the Django framework, the command-line interactive connection is adapted to obtain a database command-line interactive environment adapted to the Django framework.

[0068] This method launches a native command-line tool for the database based on client-side startup configuration parameters. Specifically, it can either read the GBase8s database connection information from the Django framework configuration, generate startup parameters that conform to the requirements of the GBase8s database command-line tool, and launch the native command-line tool via a system call, establishing a command-line interaction channel between the service and the database; or it can encapsulate the GBase8s command-line startup interface to receive command-line requests from the Django framework, automatically assemble valid startup parameters, and complete tool initialization and connection establishment. This solves the problem that the GBase8s database command-line tool cannot be directly called by the Django framework, achieving standardized startup for dedicated tools.

[0069] Based on the command-line execution rules of the Django framework, the command-line interactive connection is adapted to obtain a database command-line interactive environment compatible with the Django framework. Specifically, the input, output, exception messages, and execution results of the GBase8s database command-line connection are formatted according to the standard specifications of the Django framework, making them conform to the command-line execution habits of the Django framework. This avoids the Django framework's inability to recognize or handle exceptions due to differences in the output format and interaction logic of the native GBase8s database tools, thus achieving compatibility between the GBase8s command-line tool and the Django framework, distinct from surface data conversion.

[0070] The database adaptation method based on the Django framework provided in this application starts the native GBase8s command-line tool and establishes an interactive connection through dedicated startup parameters. Then, it performs adaptation processing according to the Django command-line rules, and finally generates a unified command-line interactive environment that can be directly used by Django. This achieves deep compatibility between the Django framework and the GBase8s database command-line level, solves the problem that the Django framework cannot call the GBase8s database command-line tool, and fills the adaptation gap of existing adaptation solutions in command-line interactive scenarios.

[0071] In some embodiments of this application, the validity verification of the database connection includes: Register a request start signal in the Django framework and bind the validity verification to the request start signal of the Django framework so as to trigger the execution of the validity verification when the database request is initiated; The method further includes: If the validity check fails, an exponential backoff retry mechanism is used to reconnect, retrying to establish the database connection at exponentially increasing time intervals until the validity check passes or a preset stopping condition is met.

[0072] The request start signal refers to the built-in signal (Signal) of the Django framework, which is automatically triggered by the framework at the initial stage of the database request and is used to associate various preprocessing logics (such as connection validity verification in the embodiments of this application).

[0073] In this embodiment, custom validation logic is registered with the Django framework's request start signal so that the validation logic is automatically executed when the signal is triggered. For example, the Django framework's `signal` module can be used to register a built-in request start signal (such as the `request_started` signal), a custom validation function can be written, and the validation function can be associated with the signal through a signal binding method (such as the `connect` method). When the signal is triggered (when a database request is initiated), the validation logic is automatically executed. This avoids invalid connections from entering subsequent adaptation and interaction processes, reduces resource waste, and integrates validation with the Django framework's database request process, eliminating the need to manually call the validation method in every database request and reducing redundant code.

[0074] The exponential backoff retry mechanism refers to dynamically adjusting the reconnection interval in an exponentially increasing manner. Specifically, if the validity check fails, the connection is retried sequentially at exponential intervals. After each reconnection, the validity check is re-executed. If the maximum number of attempts or the maximum duration are reached without success, reconnection is stopped and an exception is thrown. Alternatively, the exponential backoff parameters can be dynamically adjusted based on the connection characteristics of the GBase8s database: when the database is detected to be under high load, the initial reconnection interval is appropriately extended to avoid high-frequency reconnections exacerbating database pressure; if the database is detected to have recovered, the interval is shortened to improve reconnection efficiency.

[0075] The database adaptation method based on the Django framework provided in this application automatically triggers connection validity verification when a database request is initiated by registering and binding a request start signal in the Django framework. When the verification fails, an exponential backoff retry mechanism is used to re-establish the connection until the verification passes or the preset stopping condition is met. The verification logic is integrated with the Django framework signal mechanism to achieve automatic triggering, eliminating the need to manually call the verification method in every database request. It can also effectively prevent invalid connections from entering subsequent adaptation and interaction processes. The exponential backoff retry mechanism can avoid the waste of system resources caused by simple retries (such as fixed intervals and high-frequency retries).

[0076] In some embodiments, the method further includes: The functional characteristics of the GBase8s database are determined, and based on these characteristics, the feature detection criteria that the Django framework can call are determined. Based on these feature detection criteria, the actual functional support capabilities of the GBase8s database are identified, and the query generation logic and execution strategy are dynamically adjusted so that the generated query operations are compatible with the functional characteristics of the GBase8s database.

[0077] The database adaptation method based on the Django framework provided in this application helps to solve problems such as query execution failure and low efficiency caused by differences in database functions by identifying the functional characteristics of the GBase8s database and dynamically adjusting the Django query strategy, thus achieving deep adaptation between the Django framework and the GBase8s database. In some embodiments, the method further includes: Configure the test database to be isolated from the runtime environment database, and implement the functions of creating and destroying the test database; By adapting to the Django framework's test database management mechanism and through isolation configuration, database operations during the testing process are ensured to be performed independently without affecting the data security of the runtime environment.

[0078] The database adaptation method based on the Django framework provided in this application embodiment achieves database isolation between the test environment and the runtime environment, avoids interference with runtime environment data during the test process, effectively ensures the security and integrity of runtime environment data, adapts to the native test management mechanism of the Django framework, and helps improve test efficiency.

[0079] In some embodiments, the method further includes: Obtain the cursor object corresponding to the database connection, and submit the data operation execution statement, structure change execution statement, and structure query execution statement to the cursor object; The cursor object executes various submitted SQL statements and receives the execution status results and data result sets returned by the database. The received execution results and result sets are organized and synchronously fed back to the Django framework for further processing.

[0080] The database adaptation method based on the Django framework provided in this application implements unified submission and execution of various SQL statements through cursor objects, standardizes the interaction link between the Django framework and the GBase8s database, reduces interaction redundancy, and helps improve statement execution efficiency; and standardizes and synchronously feeds back the execution results so that the Django framework can recognize and parse the returned results, thus improving the practicality of the adaptation method.

[0081] The database adaptation method based on the Django framework provided in this application can be executed by a database adaptation device based on the Django framework. This application uses the execution of the database adaptation method based on the Django framework by a database adaptation device as an example to illustrate the database adaptation device based on the Django framework provided in this application.

[0082] Figure 3 This is a schematic diagram of the structure of a database adaptation device based on the Django framework provided in some embodiments of this application. For example... Figure 3 As shown, the database adapter 300 based on the Django framework includes: The connection module 301 is used to establish a database connection between the service and the GBase8s database according to the connection parameters of the GBase8s database, wherein the service is built based on the Django framework; The verification module 302 is used to respond to database requests initiated through the Django framework and verify the validity of the database connection; The adaptation module 303 is used to perform corresponding adaptation processing according to the type of the database request when the validity verification is passed, and generate target interactive content adapted to the GBase8s database. The interaction module 304 is used to interact with the GBase8s database according to the target interaction content, and perform corresponding adaptation processing on the interaction result to obtain a database request result adapted to the Django framework.

[0083] In some embodiments, the type of the database request includes at least one of the following: data manipulation request, database migration request, database introspection request, and command-line interaction request; Adapter module 303 is used for: If the database request is a data operation request, the SQL statement corresponding to the data operation request is converted into an execution SQL statement adapted to the GBase8s database according to the preset field mapping rules and the syntax rules of the GBase8s database. If the database request is a database migration request, the SQL statement corresponding to the database migration request is converted into an execution SQL statement adapted to the GBase8s database according to the preset structure change SQL template. If the database request is a database introspection request, generate a structure query SQL statement adapted to the GBase8s database according to the field mapping rules; If the database request is a command-line interactive request, generate client startup configuration parameters adapted to the GBase8s database.

[0084] In some embodiments, converting the SQL statement corresponding to the data operation request into an executable SQL statement adapted to the GBase8s database according to preset field mapping rules and the syntax rules of the GBase8s database includes: Determine the default values ​​for the fields in the SQL statement and the fields of type JSON; Based on the syntax rules of the GBase8s database, the default values ​​of the fields are adapted and determined. The default values ​​of fields that are determined to be incompatible with the GBase8s database through the adaptation judgment will be converted into null value identifiers that are compatible with the GBase8s database. According to the syntax rules of the database, the JSON type field data in the SQL statement is serialized to make the format of the JSON type field data adapt to the GBase8s database.

[0085] In some embodiments, the field mapping rules are also used for: When the SQL statement includes a model field type for storing short strings, the model field type is mapped to the variable-length string field type of the GBase8s database.

[0086] In some embodiments, the interaction module 304 is used for: If the database request is a database introspection request, execute the structure query SQL statement to query the system tables of the GBase8s database and obtain the structure data of the GBase8s database. The structured data is adapted based on the field mapping rules to generate model structured data adapted to the Django framework.

[0087] In some embodiments, the interaction module 304 is used for: If the database request is a command-line interaction request, start the database's native command-line tool based on the client startup configuration parameters, and establish a command-line interaction connection between the service and the database; Based on the command-line execution rules of the Django framework, the command-line interactive connection is adapted to obtain a database command-line interactive environment adapted to the Django framework.

[0088] In some embodiments, the verification module 302 is configured to: register a request initiation signal in the Django framework and bind the validity verification to the request initiation signal of the Django framework, so as to trigger the execution of the validity verification when the database request is initiated; The connection module 301 is also used for: If the validity check fails, an exponential backoff retry mechanism is used to reconnect, retrying to establish the database connection at exponentially increasing time intervals until the validity check passes or a preset stopping condition is met.

[0089] The database adaptation device based on the Django framework in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the specific implementation.

[0090] The database adaptation device based on the Django framework in this application embodiment can be a device with an operating system. This operating system can be a Microsoft (Windows) operating system, an Android operating system, an iOS operating system, or other possible operating systems; this application embodiment does not specifically limit it.

[0091] The database adaptation device based on the Django framework provided in this application embodiment can implement all the processes implemented in the above-described database adaptation method embodiment based on the Django framework, and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0092] In some embodiments, such as Figure 4 As shown, this application embodiment also provides an electronic device 400, including a processor 401, a memory 402, and a computer program stored on the memory 402 and executable on the processor 401. When the program is executed by the processor 401, it implements the various processes of the above-described database adaptation method embodiment based on the Django framework and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0093] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0094] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described database adaptation method embodiment based on the Django framework and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0095] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0096] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described database adaptation method based on the Django framework.

[0097] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0098] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described database adaptation method embodiment based on the Django framework, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0099] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0100] It should be noted that the information (including but not limited to database requests, target interactive content, etc.), data (including but not limited to data used for analysis, stored data, and displayed data) and signals (including but not limited to signals transmitted between user terminals and other devices) involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0101] For example, the aforementioned database adaptation device based on the Django framework can be used in financial institutions, public transportation, and education. Financial institutions include, but are not limited to, banks, securities firms, and insurance companies; public transportation includes, but is not limited to, subway stations, high-speed rail stations, and airports; and education includes, for example, exam rooms and classroom attendance tracking. In all these scenarios, full authorization has been obtained from all parties before data is retrieved through the Django-based database adaptation device.

[0102] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0103] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0104] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0105] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0106] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. A database adaptation method based on the Django framework, characterized in that, include: Based on the connection parameters of the GBase8s database, a database connection is established between the service and the GBase8s database, wherein the service is built based on the Django framework; In response to database requests initiated through the Django framework, the validity of the database connection is verified. If the validity verification passes, the corresponding adaptation process is performed according to the type of the database request to generate target interactive content adapted to the GBase8s database. The interaction is performed with the GBase8s database based on the target interaction content, and the corresponding adaptation processing is performed on the interaction result to obtain the database request result adapted to the Django framework.

2. The method according to claim 1, characterized in that, The types of database requests include at least one of the following: data operation requests, database migration requests, database introspection requests, and command-line interaction requests. The step of performing corresponding adaptation processing based on the type of the database request to generate target interactive content adapted to the GBase8s database includes at least one of the following: If the database request is a data operation request, the SQL statement corresponding to the data operation request is converted into an execution SQL statement adapted to the GBase8s database according to the preset field mapping rules and the syntax rules of the GBase8s database. If the database request is a database migration request, the SQL statement corresponding to the database migration request is converted into an execution SQL statement adapted to the GBase8s database according to the preset structure change SQL template. If the database request is a database introspection request, generate a structure query SQL statement adapted to the GBase8s database according to the field mapping rules; If the database request is a command-line interactive request, generate client startup configuration parameters adapted to the GBase8s database.

3. The method according to claim 2, characterized in that, The step of converting the SQL statement corresponding to the data operation request into an executable SQL statement adapted to the GBase8s database according to the preset field mapping rules and the syntax rules of the GBase8s database includes: Determine the default values ​​for the fields in the SQL statement and the fields of type JSON; Based on the syntax rules of the GBase8s database, the default values ​​of the fields are adapted and determined. The default values ​​of fields that are determined to be incompatible with the GBase8s database through the adaptation judgment will be converted into null value identifiers that are compatible with the GBase8s database. According to the syntax rules of the database, the JSON type field data in the SQL statement is serialized to make the format of the JSON type field data adapt to the GBase8s database.

4. The method according to claim 2 or 3, characterized in that, The field mapping rules are also used for: When the SQL statement includes a model field type for storing short strings, the model field type is mapped to the variable-length string field type of the GBase8s database.

5. The method according to claim 2, characterized in that, The step of interacting with the GBase8s database based on the target interaction content and performing corresponding adaptation processing on the interaction result to obtain a database request result adapted to the Django framework includes: If the database request is a database introspection request, execute the structure query SQL statement to query the system tables of the GBase8s database and obtain the structure data of the GBase8s database. The structured data is adapted based on the field mapping rules to generate model structured data adapted to the Django framework.

6. The method according to claim 2 or 5, characterized in that, The step of interacting with the GBase8s database based on the target interaction content and performing corresponding adaptation processing on the interaction results to obtain a database request result adapted to the Django framework includes: If the database request is a command-line interaction request, start the database's native command-line tool based on the client startup configuration parameters, and establish a command-line interaction connection between the service and the database; Based on the command-line execution rules of the Django framework, the command-line interactive connection is adapted to obtain a database command-line interactive environment adapted to the Django framework.

7. The method according to claim 1, characterized in that, The validation of the database connection includes: Register a request start signal in the Django framework and bind the validity verification to the request start signal of the Django framework so as to trigger the execution of the validity verification when the database request is initiated; The method further includes: If the validity check fails, an exponential backoff retry mechanism is used to reconnect, retrying to establish the database connection at exponentially increasing time intervals until the validity check passes or a preset stopping condition is met.

8. A database adaptation device based on the Django framework, characterized in that, The connection module is used to establish a database connection between the service and the GBase8s database based on the connection parameters of the GBase8s database. The service is built based on the Django framework. The verification module is used to respond to database requests initiated through the Django framework and verify the validity of the database connection. The adaptation module is used to perform corresponding adaptation processing according to the type of the database request when the validity verification passes, and generate target interactive content adapted to the GBase8s database. The interaction module is used to interact with the GBase8s database according to the target interaction content, and to perform corresponding adaptation processing on the interaction results to obtain the database request results adapted to the Django framework.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the database adaptation method based on the Django framework as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the database adaptation method based on the Django framework as described in any one of claims 1 to 7.