CN113609140A - Database operation method and system based on programming language Python - Google Patents

Database operation method and system based on programming language Python Download PDF

Info

Publication number
CN113609140A
CN113609140A CN202111178873.8A CN202111178873A CN113609140A CN 113609140 A CN113609140 A CN 113609140A CN 202111178873 A CN202111178873 A CN 202111178873A CN 113609140 A CN113609140 A CN 113609140A
Authority
CN
China
Prior art keywords
database
accessed
target
data
calling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111178873.8A
Other languages
Chinese (zh)
Inventor
王海燕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
AVIC INTERNATIONAL E-BUSINESS Inc
Original Assignee
AVIC INTERNATIONAL E-BUSINESS Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by AVIC INTERNATIONAL E-BUSINESS Inc filed Critical AVIC INTERNATIONAL E-BUSINESS Inc
Priority to CN202111178873.8A priority Critical patent/CN113609140A/en
Publication of CN113609140A publication Critical patent/CN113609140A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

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

Abstract

The invention discloses a database operation method and a system based on a programming language Python, wherein the method comprises the following steps: acquiring a service operation request, wherein the service operation request is used for requesting the operation processing of target data on a database to be accessed; and calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed. The invention can solve the problems of complex database operation process, inconvenient operation, low performance and the like in the prior art.

Description

Database operation method and system based on programming language Python
Technical Field
The invention relates to the technical field of data processing, in particular to a database operation method and system based on a programming language Python.
Background
With the rapid development of cloud computing technology, cloud computing services provided by a cloud computing platform are more and more abundant. The cloud database service is one of widely used cloud computing services, and the cloud database service is used for a user to use different types of databases for data storage by deploying various types of databases on a cloud server.
Currently, in a known cloud database system, each type of cloud database is configured with a corresponding database operation flow to implement corresponding operation processing of the database. However, in practical applications, databases of various types and versions are usually used for data storage according to market and customer requirements. Therefore, when the operation processing is performed on the databases of different types, different database operation flows need to be switched back and forth and access the databases of different types, and the system cannot provide a uniform access form, so that the database operation flow is complex and the operation is not simple and convenient, and the performance of the database operation is reduced.
Disclosure of Invention
The embodiment of the application provides a database operation method based on a programming language Python, and solves the problems that the database operation process is complex, the operation is not simple and convenient, the performance is low and the like in the prior art.
In one aspect, an embodiment of the present application provides a database operation method based on a programming language Python, which is applied to a database operating system, where the database operating system includes different types of databases and operation functions provisioned for each type of database, and the method includes:
acquiring a service operation request, wherein the service operation request is used for requesting the operation processing of target data on a database to be accessed;
and calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed.
Optionally, the service operation request carries connection information of the database to be accessed, where the connection information is used to indicate a data source object of the database to be accessed.
Optionally, before the invoking a target operation function provisioned for the database to be accessed in the database operating system, the method further includes:
acquiring the type of a database to be accessed;
installing a target Python library corresponding to the type of the database to be accessed, wherein the database operating system comprises an initial Python library configured for different types of databases, and the initial Python library is in one-to-one correspondence with the type of the database;
newly configuring the target operation function in the target Python library;
the target operation function is used for performing corresponding operation processing on the database to be accessed, and the target operation function comprises at least one of the following method functions: initializing a data source object, connecting a connect method, deleting a table drop _ table method, creating a table create _ sample _ table method, inserting a table insert _ sample _ data method, selecting a select method, and closing a close method.
Optionally, before installing the target Python library corresponding to the type of the database to be accessed, the method further includes:
configuring corresponding initial Python libraries for different types of databases;
the initial Python library is in one-to-one correspondence with the type of the database, and the initial Python library is used for providing basic operation service for the database of the type corresponding to the initial Python library.
Optionally, the target operation function includes a connect method, the calling the target operation function provisioned for the database to be accessed in the database operation system, and processing the service operation request includes:
and calling the connect method, connecting the connect method to the database to be accessed through remote calling, and initializing the cursor of the database to be accessed.
Optionally, the target operation function further includes a table deleting drop _ table method, and the invoking a target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table deleting drop _ table method, and deleting the target data in the database to be accessed through the transmitted table name.
Optionally, the target operation function further includes a table creation _ sample _ table method, the invoking a target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table creation _ sample _ table method, and writing the target data into the database to be accessed in a sample table mode.
Optionally, the target operation function further includes a table insert _ sample _ data method, and the invoking the target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table insertion _ sample _ data method, and inserting the target data into the database to be accessed through the incoming table name and the number of insertion rows and columns.
Optionally, the selecting method is further included in the target operation function, the calling the target operation function provisioned for the to-be-accessed database in the database operation system, and processing the service operation request, so that the operation processing of the target data in the to-be-accessed database further includes:
and calling the select method, inquiring in the database to be accessed through an incoming query SQL statement and returning the target data.
Optionally, the target operation function further includes a close method, the calling the target operation function provisioned for the database to be accessed in the database operation system, and the processing the service operation request further includes:
and calling the close method, closing the connection of the database to be accessed and closing the cursor of the database to be accessed.
On the other hand, the present application provides a database operating device based on a programming language Python, which is applied to a database operating system, where the database operating system includes different types of databases and operation functions provisioned for each type of database, and the device includes: the device comprises an acquisition module and a processing module, wherein:
the acquisition module is used for acquiring a service operation request, and the service operation request is used for requesting the operation processing of target data on the database to be accessed;
the processing module is configured to call a target operation function provisioned for the to-be-accessed database in the database operating system, and process the service operation request, so as to perform operation processing on the target data in the to-be-accessed database.
For the content that is not introduced or not described in the embodiment of the present application, reference may be made to the related descriptions in the foregoing method embodiments, and details are not described here again.
In another aspect, an embodiment of the present application provides a database operating system based on a programming language Python, where the system includes: a processor, a memory, a communication interface, and a bus; the processor, the memory and the communication interface are connected through the bus and complete mutual communication; the memory stores executable program code; the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the database operation method based on the programming language Python.
On the other hand, the present application provides a computer-readable storage medium by an embodiment of the present application, where the computer-readable storage medium stores a program, and when the program runs on a terminal device, the program performs the method for operating a database based on the programming language Python as described above.
One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: the method comprises the steps of obtaining a service operation request, calling a target operation function which is pre-configured for the database to be accessed in the database operation system to process the service operation request, and performing operation processing on target data in the database to be accessed. The method and the device have the advantages that corresponding operation functions are configured for different types of databases in the database operation system in advance, and then the preset target operation functions can be directly called to realize corresponding operation processing of the database to be accessed when the database to be accessed is operated. Therefore, the system can be compatible with various databases of different types, can provide simple and rapid access operation processing for the databases of different types, and can solve the problems of complex database operation flow, inconvenient operation, low performance and the like in the prior art.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a database operation method based on a programming language Python according to an embodiment of the present disclosure.
Fig. 2 is a schematic flowchart of another database operating method based on the programming language Python according to an embodiment of the present disclosure.
Fig. 3 is a schematic flowchart of another database operating method based on the programming language Python according to an embodiment of the present disclosure.
Fig. 4 is a schematic structural diagram of a database operating device based on a programming language Python according to an embodiment of the present disclosure.
Fig. 5 is a schematic structural diagram of a database operating system based on the programming language Python according to an embodiment of the present disclosure.
Detailed Description
The embodiment of the application provides a database operation method based on a programming language Python, and solves the technical problems that the database operation process is complex, the operation is not simple and convenient, the performance is low and the like in the prior art.
In order to solve the technical problems, the general idea of the embodiment of the application is as follows: acquiring a service operation request, wherein the service operation request is used for requesting the operation processing of target data on a database to be accessed; and calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed.
In order to better understand the technical solution, the technical solution will be described in detail with reference to the drawings and the specific embodiments.
First, it is stated that the term "and/or" appearing herein is merely one type of associative relationship that describes an associated object, meaning that three types of relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Fig. 1 is a schematic flowchart of a database operation method based on a programming language Python according to an embodiment of the present disclosure. The method shown in fig. 1 is applied to a database operating system (hereinafter, referred to as a database operating system) based on a programming language Python, and specifically includes the following implementation steps:
s101, obtaining a service operation request, wherein the service operation request is used for requesting to perform operation processing on target data of a database to be accessed.
The service operation request is sent by a client or generated by the database operating system, and is determined according to actual requirements, which is not limited in the present application. The service operation request is used for requesting operation processing of target data, such as data reading processing, data writing processing or other operation data, on a database to be accessed of the system.
Optionally, the service operation request carries connection information of the database to be accessed, where the connection information is used to indicate a data source object in the database to be accessed, such as an access address/domain name host, a port post, a user name, a password, a database name, and the like of the database.
S102, calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed.
The method and the device call a target operation function which is configured for the database to be accessed in advance in the database operation system to process the service operation request so as to perform operation processing on the target data in the database to be accessed.
The target operation function is some functions of the system repackaging on the basis of the target Python library, and may include, but is not limited to, at least one of the following method functions: initializing data source objects, connecting connect method, deleting table drop table method, creating table create table sample table method, inserting table insert sample data method, selecting select method, closing close method or other packing method. The configuration of the target operation function is specifically described in detail below in the present application.
Several embodiments of step S102 are described below.
In a specific embodiment, the target operation function includes an initialization data source object, and the application may initialize the data source object that is to be accessed and is transmitted to the database, such as an initialization host, a port post, a user name, a password, a database name, and the like.
In another embodiment, the target operation function includes a connect method, and the application may call the connect method, connect to the database to be accessed through remote call, and initialize a cursor of the database to be accessed.
In another specific embodiment, the target operation function includes a table deletion drop _ table method, and the target operation function may call the table deletion drop _ table method to delete the target data in the database to be accessed by introducing a table name.
In another specific embodiment, the target operation function includes a table creation _ sample _ table method, and the application may call the table creation _ sample _ table method, and write the target data in the to-be-accessed database in the form of a sample table.
In yet another embodiment, the target operation function comprises a table insert _ sample _ data method, and the present application may call the table insert _ sample _ data method to insert the target data into the database to be accessed through an incoming table name and an insert row number.
In another embodiment, the target operation function includes a select method, and the application may call the select method, query the to-be-accessed database through an incoming query SQL statement, and return the target data.
In yet another embodiment, the target operation function includes a close method, and the application can call the close method, close the connection of the database to be accessed, and close the cursor of the database to be accessed.
Optionally, before step S102, the present application may configure corresponding operation functions for different types of databases. For an example, the present application provides an example of configuring a target operation function for the database to be accessed, and please refer to fig. 2, which is a flowchart of another database operation method based on a programming language Python according to an embodiment of the present application. The method shown in fig. 2 specifically includes the following implementation steps:
s201, configuring corresponding initial Python libraries for different types of databases, wherein the initial Python libraries correspond to the types of the databases one by one, and the initial Python libraries are used for providing basic operation services for the type of the databases corresponding to the initial Python libraries.
The application can use a programming language Python to configure the corresponding initial Python library for different types of databases, and the initial Python library can provide basic operation services for the corresponding types of databases, which can be understood as providing an open source framework. Wherein, a type of database corresponds to an initial Python library, that is, the initial Python library corresponds to the type of the database one by one.
It is understood that different types of databases include, but are not limited to, for example, a MySQL database, a PostgreSQL database, an Oracle database, a Microsoft SQL Server database, a DB2 database, a Mongo database, a Redis database, an ElasticSearch database, a ClickHouse database, an HBase database, an HDFS database, a Hive database, an Impala database, an FTP database, or other types of databases. The preset database connection tool can be used for connecting to the corresponding type of database, and is system-defined, and for example, the preset database connection tool can be a SQLAlchemy tool. The SQLAlchemy is based on an open source ORM framework, which models data in its most basic form. At present, the database supported by SQLAlchemy is limited, for example, the database supports connection of MySQL database, PostgreSQL database, Oracle database, Microsoft SQL Server database, SQLite database and the like.
Several initial Python libraries configured for different types of databases of the present application are exemplified below.
pymysql (initial Python library) is a Python library configured for the MySQL database, i.e. a Python library used to operate the MySQL database. According to the method, a connection object (connect) is created by initializing connection information, a cursor () function in the connection object can acquire a cursor object, subsequent SQL execution operation can execute ()/execute according to the cursor object and can also acquire an executed return result fetcall (), and finally the cursor object and the connection object close () are closed. Functions for creating a user sample table and inserting user test data are added in the automatic tool dtautomation tools, the table is created through a specified table creating statement, and the user test data are inserted.
psycpg 2 is a Python library used to manipulate PostgreSQL and used essentially the same as pymysql. Functions for creating a user sample table and inserting user test data are added in dtautomation tools, the table is created through a specified table creating statement, and the user test data are inserted.
cx _ Oracle is a Python library used to manipulate Oracle and is also used substantially the same as pymysql. However, before initializing the connection object, dsn needs to be parsed into tns string by makedsn (), and when the binding variable is used in sql, the identification position parameter needs to be used. The functions of creating the user sample and inserting the user test data are added in the dtautomation tools, the table is created by specifying a table creating statement, and the user test data is inserted.
Pymsql is a Python library used to operate SQLServer, and is also used in essentially the same way as pymysql. The functions of creating the user sample and inserting the user test data are added in the dtautomation tools, the table is created by specifying a table creating statement, and the user test data is inserted. And a function for starting CDC is added, and the CDC function of the specified table is started.
ibm-DB is a Python library used to operate DB2, and is also used in essentially the same way as pymysql. The functions of creating the user sample and inserting the user test data are added in the dtautomation tools, the table is created by specifying a table creating statement, and the user test data is inserted. And adds a function to determine if the user acquisition table exists.
Pymnogo is a Python library used for operating Mongodb, and Mongodb can be directly operated after connection information is initialized. The function of inserting user test data is added in dtautomation tools to insert user test data.
The Redis-py-cluster is a Python library used for operating the Redis cluster, creates a Redis cluster object by initializing connection information, and then inserts/acquires data through the connection object. The function of inserting user test data is added in dtautomation tools to insert user test data.
The Redis is a Python library for operating the Redis standalone mode and the sentinel mode, creates a Redis standalone connection object or a Redis sentinel connection object by initializing connection information, and then inserts/acquires data through the connection object. The function of inserting user test data is added in dtautomation tools to insert user test data.
The ElasticSearch is a Python library used for operating the ElasticSearch, creates a connection object by initializing connection information, and performs data operation through the connection object. The functions of creating a user sample index and inserting user test data are added to dtautomation tools.
The ClickHouse-driver is a Python library used to manipulate ClickHouse, and is also used in essentially the same way as pymysql. Functions for creating a user sample table and inserting user test data are added in dtautomation tools, the table is created through a specified table creating statement, and the user test data are inserted.
The HBase-Python is a Python library used for operating the HBase, a connection object is created by initializing connection information, HBase PATHs (PATH _ MASTER and PATH _ META _ REGION) in the HBase-Python are fixed, and HBases of other PATHs cannot directly use the HBase-Python. When the dtautomation tools initialize the connection information, the values of PATH _ MASTER and PATH _ META _ REGION are rewritten to support the operation of HBase of other PATHs, and the dtautomation tools add a function for inserting user test data.
Hdfs is a Python library for operating Hdfs, acquires a connection object by initializing connection information, and then can perform operations such as viewing subdirectory information list (), creating directory makedirs (), uploading file upload (), downloading file download (), reading file read (), writing file write (), and the like through the connection object.
Paramiko is a Python library for operating an FTP server, acquires a connection object by initializing connection information, and then can perform operations of viewing subdirectory information list (), creating directory makedirs (), uploading file upload (), downloading file download (), reading file read (), writing file write (), and the like through the connection object. The paramiko only supports reading and writing of files, and uploading, downloading and deleting of folders are realized in dtautomation tools.
S202, obtaining the type of the database to be accessed.
S203, installing a target Python library corresponding to the type of the database to be accessed, wherein the target Python library is a Python library matched with the type of the database to be accessed in the plurality of initial Python libraries.
The method and the device for accessing the data base can determine the type of the data base to be accessed first, and then determine a target Python base matched with the type of the data base to be accessed from a plurality of initial Python bases configured in S201. And finally, installing the target Python library in the database operating system to provide corresponding basic operation service for the database to be accessed. And the subsequent custom configuration of some target operation functions in the target Python library (basic framework) is facilitated.
S204, newly configuring the target operation function in the target Python library.
The target operation functions are some functions repackaged by the system on the basis of the target Python library, and are used for performing corresponding operation processing on the database to be accessed. The target operation function includes, but is not limited to, at least one of the following method functions: initializing data source objects, connecting connect method, deleting table drop table method, creating table create table sample table method, inserting table insert sample data method, selecting select method, closing close method or other packing method.
The following specifically describes relevant contents by taking the target operation function as an example, including a data source object initialization method, a connect method, a table delete drop _ table method, a table create _ sample _ table method, a table insert _ sample _ data method, a select method, and a close method. Please refer to fig. 3, which is a flowchart illustrating another possible database operation method based on the programming language Python according to an embodiment of the present application. The method shown in fig. 3 comprises:
s301, installing a target Python library corresponding to the database to be accessed in the database operating system.
S302, initializing a data source object, namely initializing the data source object of the database to be accessed.
After the target Python library corresponding to the database to be accessed is imported into the database operating system, the data source object in the database to be accessed can be initialized, for example, the incoming data source object information of the database, such as the access address/domain name host, the port post, the user name, the password, the database name and the like, is initialized.
S303, packaging and connecting the connect method.
The method for configuring/packaging the connection is convenient for calling the connection function to realize the remote connection and cursor initialization of the database to be accessed.
S304, packaging and deleting a table drop _ table method.
The method for configuring the drop _ table realizes direct deletion operation on the table data corresponding to the table name by transmitting the table name.
S305, a package creation table create _ sample _ table method.
The method for configuring the create _ sample _ table is used for creating a user information sample table, wherein table fields included in the sample table are set by a system user, are usually default/fixed, and are not limited in the application.
S306, packing table insert _ sample _ data method.
According to the method for configuring insert _ sample _ data, the user inserts sample data into the sample table corresponding to the incoming table name through the incoming table name and the number of the inserted rows and columns, so that the creation of fake data (fake data) is realized, and further user test data is constructed.
Understandably, some test data including but not limited to user name, gender, birthday, ID card, phone number, mailbox address, and home address, etc. is produced when implementing insert sample data method. These data are a series of simulated data, not random strings or numbers. According to the method and the device, information such as the user name, the city area code, the mobile phone number prefix and the mailbox suffix can be used as basic data, random combination splicing (such as combination of the user name and the mobile phone number) is carried out on the basic data, simulated user data are realized, and the name, the gender, the birthday and the identification number information in the user information can be matched with each other.
S307, a package selection method.
The method for configuring the select is characterized in that a query SQL statement is directly transmitted, query of a query function in the select method is called, and a corresponding query result is returned.
And S308, packaging and closing close method.
The method is configured to close the connection of the database to be accessed and close the cursor.
To assist the user in better understanding the above embodiments, two specific example codes are described below.
Taking the example of the connection operation kafka database, by transferring the brooker address (also understood as a connection address) of kafka, the kafka object initialization is realized, and then calling batch _ sample _ producer to transfer the topic name, the production data amount and the interval time, one piece of data can be driven in every one second, and 10 pieces of data are driven in total. The specific implementation pseudo code is as follows:
```python
from dtautomationtools.dataSourceTools.kafka.kafkaTool import MyKafkaProducer
myProducer = MyKafkaProducer(["172.16.100.109:9092"])
myProducer.batch_sample_producer('test', 10, 1)
myProducer.close()
```
taking a connection operation mysql database as an example, the mysql object is initialized by introducing a host, a port, a database name, a user name and a password, call connect () to connect the mysql database, call drop _ table to delete table shirer _ py, call create sample table shirer _ py, call insert _ sample _ data to insert 10 pieces of data in the shirer _ py table. The specific implementation pseudo code is as follows:
```python
from dtautomationtools.dataSourceTools.mysql.mysqlTool import MyPymysql
mypyMysql = MyPymysql('172.16.100.186', '3306', 'test', 'Abc123456', 'test')
# connect
mypyMysql.connect()
tableName = 'test.shier_py'
mypyMysql.drop_table(tableName)
mypyMysql.create_sample_table(tableName)
mypyMysql.insert_sample_data(tableName, 10)
mypyMysql.close()
```
the method and the system realize the operation of integrating various databases (also called as data sources), and are beneficial to conveniently and quickly establishing test data when the interfaces of various database functions are automated. A user only needs to uniformly install the database operating system of the application, the system can automatically install the required functional module, and sample data or other custom data are quickly generated through a packaged method. The user does not need to care about how to operate the database, and can complete corresponding operation processing only by inputting the table name.
By implementing the method, the service operation request is obtained, the target operation function which is pre-configured for the database to be accessed in the database operation system is called to process the service operation request, and the target data is operated and processed in the database to be accessed. The method and the device have the advantages that corresponding target operation functions are configured for different types of databases to be accessed in the database operation system in advance, and then the preset target operation functions can be directly called to realize corresponding operation processing of the databases to be accessed when the databases to be accessed are operated. Therefore, the system can be compatible with various databases of different types, can provide simple and rapid access operation processing for the databases of different types, and can solve the problems of complex database operation flow, inconvenient operation, low performance and the like in the prior art.
Based on the same inventive concept, another embodiment of the present application provides a device and a system corresponding to the method for operating a database based on a programming language Python in the embodiment of the present application.
Referring to fig. 4, a database operating apparatus based on a programming language Python according to an embodiment of the present disclosure includes an obtaining module 401 and a processing module 402, where:
the obtaining module 401 is configured to obtain a service operation request, where the service operation request is used to request to perform operation processing on target data on a database to be accessed;
the processing module 402 is configured to invoke a target operation function provisioned for the to-be-accessed database in the database operating system, and process the service operation request, so as to perform operation processing on the target data in the to-be-accessed database.
Optionally, the service operation request carries connection information of the database to be accessed, where the connection information is used to indicate a data source object of the database to be accessed.
Optionally, the apparatus further comprises an installation module 403 and a configuration module 404, wherein:
the obtaining module 401 is further configured to obtain a type of a database to be accessed;
the installation module 403 is configured to install a target Python library corresponding to the type of the database to be accessed, where the database operating system includes an initial Python library configured for different types of databases, and the initial Python libraries correspond to the types of the databases one to one;
the configuration module 404 is configured to newly configure the target operation function in the target Python library; the target operation function is used for performing corresponding operation processing on the database to be accessed, and the target operation function comprises at least one of the following method functions: initializing a data source object, connecting a connect method, deleting a table drop _ table method, creating a table create _ sample _ table method, inserting a table insert _ sample _ data method, selecting a select method, and closing a close method.
Optionally, the target operation function includes a connect method, and the processing module 402 is specifically configured to:
and calling the connect method, connecting the connect method to the database to be accessed through remote calling, and initializing the cursor of the database to be accessed.
Optionally, the target operation function includes a table deletion drop _ table method, and the processing module 402 is specifically configured to:
and calling the table deleting drop _ table method, and deleting the target data in the database to be accessed through the transmitted table name.
Optionally, the target operation function includes a table creation _ sample _ table method, and the processing module 402 is specifically configured to:
and calling the table creation _ sample _ table method, and writing the target data into the database to be accessed in a sample table mode.
Optionally, the target operation function includes a table insert _ sample _ data method, and the processing module 402 is specifically configured to:
and calling the table insertion _ sample _ data method, and inserting the target data into the database to be accessed through the incoming table name and the number of insertion rows and columns.
Optionally, the target operation function includes a select method, and the processing module 402 is specifically configured to:
and calling the select method, inquiring in the database to be accessed through an incoming query SQL statement and returning the target data.
Optionally, the target operation function includes a close method, and the processing module 402 is specifically configured to:
and calling the close method, closing the connection of the database to be accessed and closing the cursor of the database to be accessed.
Please refer to fig. 5, which is a schematic structural diagram of a database operating system according to an embodiment of the present application. The system 50 shown in fig. 5 comprises: at least one processor 501, a communication interface 502, a user interface 503 and a memory 504, wherein the processor 501, the communication interface 502, the user interface 503 and the memory 504 can be connected through a bus or other means, and the embodiment of the present invention is exemplified by being connected through the bus 505. Wherein,
processor 501 may be a general-purpose processor, such as a Central Processing Unit (CPU).
The communication interface 502 may be a wired interface (e.g., an ethernet interface) or a wireless interface (e.g., a cellular network interface or using a wireless local area network interface) for communicating with other terminals or websites. In this embodiment of the present invention, the communication interface 502 is specifically configured to obtain the operation request.
The user interface 503 may be a touch panel, including a touch screen and a touch screen, for detecting an operation instruction on the touch panel, and the user interface 503 may also be a physical button or a mouse. The user interface 503 may also be a display screen for outputting, displaying images or data.
The Memory 504 may include Volatile Memory (Volatile Memory), such as Random Access Memory (RAM); the Memory may also include a Non-Volatile Memory (Non-Volatile Memory), such as a Read-Only Memory (ROM), a Flash Memory (Flash Memory), a Hard Disk (Hard Disk Drive, HDD), or a Solid-State Drive (SSD); the memory 504 may also comprise a combination of the above-described types of memory. The memory 504 is used for storing a set of program codes, and the processor 501 is used for calling the program codes stored in the memory 504 and executing the following operations:
acquiring a service operation request, wherein the service operation request is used for requesting the operation processing of target data on a database to be accessed;
and calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed.
Optionally, the service operation request carries connection information of the database to be accessed, where the connection information is used to indicate a data source object of the database to be accessed.
Optionally, before the invoking of the target operation function provisioned for the database to be accessed in the database operating system, the processor 501 is further configured to:
acquiring the type of a database to be accessed;
installing a target Python library corresponding to the type of the database to be accessed, wherein the database operating system comprises an initial Python library configured for different types of databases, and the initial Python library is in one-to-one correspondence with the type of the database;
newly configuring the target operation function in the target Python library;
the target operation function is used for performing corresponding operation processing on the database to be accessed, and the target operation function comprises at least one of the following method functions: initializing a data source object, connecting a connect method, deleting a table drop _ table method, creating a table create _ sample _ table method, inserting a table insert _ sample _ data method, selecting a select method, and closing a close method.
Optionally, the target operation function includes a connect method, the calling the target operation function provisioned for the database to be accessed in the database operation system, and processing the service operation request includes:
and calling the connect method, connecting the connect method to the database to be accessed through remote calling, and initializing the cursor of the database to be accessed.
Optionally, the target operation function further includes a table deleting drop _ table method, and the invoking a target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table deleting drop _ table method, and deleting the target data in the database to be accessed through the transmitted table name.
Optionally, the target operation function further includes a table creation _ sample _ table method, the invoking a target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table creation _ sample _ table method, and writing the target data into the database to be accessed in a sample table mode.
Optionally, the target operation function further includes a table insert _ sample _ data method, and the invoking the target operation function provisioned for the to-be-accessed database in the database operation system, processing the service operation request, and performing operation processing on the target data in the to-be-accessed database further includes:
and calling the table insertion _ sample _ data method, and inserting the target data into the database to be accessed through the incoming table name and the number of insertion rows and columns.
Optionally, the selecting method is further included in the target operation function, the calling the target operation function provisioned for the to-be-accessed database in the database operation system, and processing the service operation request, so that the operation processing of the target data in the to-be-accessed database further includes:
and calling the select method, inquiring in the database to be accessed through an incoming query SQL statement and returning the target data.
Optionally, the target operation function further includes a close method, the calling the target operation function provisioned for the database to be accessed in the database operation system, and the processing the service operation request further includes:
and calling the close method, closing the connection of the database to be accessed and closing the cursor of the database to be accessed.
By implementing the method, the service operation request is obtained, the target operation function which is pre-configured for the database to be accessed in the database operation system is called to process the service operation request, and the target data is operated and processed in the database to be accessed. The method and the device have the advantages that corresponding target operation functions are configured for different types of databases to be accessed in the database operation system in advance, and then the preset target operation functions can be directly called to realize corresponding operation processing of the databases to be accessed when the databases to be accessed are operated. Therefore, the system can be compatible with various databases of different types, can provide simple and rapid access operation processing for the databases of different types, and can solve the problems of complex database operation flow, inconvenient operation, low performance and the like in the prior art.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A database operation method based on a programming language Python is applied to a database operating system, wherein the database operating system comprises different types of databases and operation functions prepared for each type of database, and the method comprises the following steps:
acquiring a service operation request, wherein the service operation request is used for requesting the operation processing of target data on a database to be accessed;
and calling a target operation function which is pre-configured for the database to be accessed in the database operation system, and processing the service operation request so as to perform operation processing on the target data in the database to be accessed.
2. The method according to claim 1, wherein the service operation request carries connection information of the database to be accessed, and the connection information is used to indicate a data source object of the database to be accessed.
3. The method of claim 1, wherein before the calling the target operation function provisioned for the database to be accessed in the database operating system, the method further comprises:
acquiring the type of a database to be accessed;
installing a target Python library corresponding to the type of the database to be accessed, wherein the database operating system comprises an initial Python library configured for different types of databases, and the initial Python library is in one-to-one correspondence with the type of the database;
newly configuring the target operation function in the target Python library;
the target operation function is used for performing corresponding operation processing on the database to be accessed, and the target operation function comprises at least one of the following method functions: initializing a data source object, connecting a connect method, deleting a table drop _ table method, creating a table create _ sample _ table method, inserting a table insert _ sample _ data method, selecting a select method, and closing a close method.
4. The method according to claim 1, wherein the target operation function includes a connect method, the calling the target operation function provisioned for the database to be accessed in the database operating system, and the processing the service operation request includes:
and calling the connect method, connecting the connect method to the database to be accessed through remote calling, and initializing the cursor of the database to be accessed.
5. The method according to claim 4, wherein the target operation function further includes a table deletion _ table method, and the invoking a target operation function provisioned in the database operating system for the database to be accessed to process the service operation request, so as to perform operation processing on the target data in the database to be accessed further includes:
and calling the table deleting drop _ table method, and deleting the target data in the database to be accessed through the transmitted table name.
6. The method according to claim 4, wherein the target operation function further includes a table creation _ sample _ table method, the calling the target operation function provisioned for the database to be accessed in the database operation system, and processing the service operation request to perform the operation processing on the target data in the database to be accessed further includes:
and calling the table creation _ sample _ table method, and writing the target data into the database to be accessed in a sample table mode.
7. The method according to claim 4, wherein the target operation function further includes a table insert _ sample _ data method, and the calling the target operation function provisioned for the database to be accessed in the database operation system to process the service operation request, so as to perform the operation processing on the target data in the database to be accessed further includes:
and calling the table insertion _ sample _ data method, and inserting the target data into the database to be accessed through the incoming table name and the number of insertion rows and columns.
8. The method of claim 4, wherein the target operation function further comprises a select method, the calling the target operation function provisioned for the database to be accessed in the database operating system, and the processing the service operation request to perform the operation processing on the target data in the database to be accessed further comprises:
and calling the select method, inquiring in the database to be accessed through an incoming query SQL statement and returning the target data.
9. The method of claim 4, wherein the target operation function further comprises a close method, the calling the target operation function provisioned for the database to be accessed in the database operating system, and the processing the service operation request further comprises:
and calling the close method, closing the connection of the database to be accessed and closing the cursor of the database to be accessed.
10. A database operating system based on a programming language Python, the system comprising: a processor, a memory, a communication interface, and a bus; the processor, the memory and the communication interface are connected through the bus and complete mutual communication; the memory stores executable program code; the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method for operating a database based on the programming language Python according to any one of the claims 1 to 9.
CN202111178873.8A 2021-10-11 2021-10-11 Database operation method and system based on programming language Python Pending CN113609140A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111178873.8A CN113609140A (en) 2021-10-11 2021-10-11 Database operation method and system based on programming language Python

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111178873.8A CN113609140A (en) 2021-10-11 2021-10-11 Database operation method and system based on programming language Python

Publications (1)

Publication Number Publication Date
CN113609140A true CN113609140A (en) 2021-11-05

Family

ID=78343485

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111178873.8A Pending CN113609140A (en) 2021-10-11 2021-10-11 Database operation method and system based on programming language Python

Country Status (1)

Country Link
CN (1) CN113609140A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115645905A (en) * 2022-10-21 2023-01-31 圣名科技(广州)有限责任公司 Method and device for cursor display, electronic equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070288890A1 (en) * 2006-05-17 2007-12-13 Ipreo Holdings, Inc. System, method and apparatus to allow for a design, administration, and presentation of computer software applications

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070288890A1 (en) * 2006-05-17 2007-12-13 Ipreo Holdings, Inc. System, method and apparatus to allow for a design, administration, and presentation of computer software applications

Non-Patent Citations (6)

* Cited by examiner, † Cited by third party
Title
BATCLUBYOYO: "https://github.com/batclubyoyo/hbase-zk-python", 《BATCLUBYOYO / HBASE-ZK-PYTHON》 *
CGGAO: "https://blog.csdn.net/weixin_30600197/article/details/95845193", 《PYTHON MYSQL-表的创建,删除和更新》 *
LFYZJCK: "https://github.com/3601314/hbase-python/commit/76fee47855e31de2b9999a271229df1542ee6210", 《SUPPORT CUSTOM HBASE ZOOKEEPER ROOT PATH》 *
LIUZH(少昊): "https://blog.csdn.net/liuzonghao88/article/details/86017401", 《PYTHON中使用PYMYSQL往MYSQL数据库中插入(INSERT)数据》 *
TAOGEYT: "https://www.cnblogs.com/liyatao/archive/2020/06/01/13027304.html", 《PYTHON通用数据库操作工具 PYDBCLIB》 *
沙漏在下雨: "https://blog.csdn.net/qq_45906219/article/details/106647526", 《简单干货,在PYTHON中 PYMYSQL 的各种小白用法!》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115645905A (en) * 2022-10-21 2023-01-31 圣名科技(广州)有限责任公司 Method and device for cursor display, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US11269660B2 (en) Methods and systems for integrated development environment editor support with a single code base
CN108293081B (en) Deep linking of program playback to mobile application state through user interface events
CN107925696B (en) System and method for identifying, indexing and navigating to a depth state of a mobile application
WO2021184725A1 (en) User interface test method and apparatus, storage medium, and computer device
US11016785B2 (en) Method and system for mirror image package preparation and application operation
CN109716324B (en) Direct table association in-memory database
US11169792B2 (en) Method and apparatus for generating patch
US20180336021A1 (en) Package installation on a host file system using a container
CN108304676B (en) Automatic reconstruction method for three-dimensional model of assembly body, terminal device and storage medium
WO2013028438A1 (en) System and method for dynamically assembling an application on a client device
CN111897623B (en) Cluster management method, device, equipment and storage medium
CN114356341B (en) Data processing method, device, equipment, storage medium and product
CN113609140A (en) Database operation method and system based on programming language Python
US10503430B2 (en) Method and device for clearing data and electronic device
CN104378393A (en) Resource sharing method and corresponding device
CN111338655A (en) Installation package distribution method and system
CN112528193A (en) Page document processing method, page document management method and device, terminal device, computer device and server
CN115016836A (en) Component version management method and device, electronic equipment and system
CN113704120A (en) Data transmission method, device, equipment and storage medium
US20140129917A1 (en) Value-added usage of process-oriented extension fields in business mashups
CN115167941A (en) Front-end component processing method, device, terminal and storage medium
CN112463202B (en) Configuration method and device of operating system functional components
Pippi Python for Google App Engine
CN113312149B (en) Password resetting method
US11294892B2 (en) Virtual archiving of database records

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20211105

RJ01 Rejection of invention patent application after publication