Updated on 2023-07-19 GMT+08:00

Database-Related SDKs

Creating a Database

DLI provides an API for creating a database. You can use the API to create a database. The sample code is as follows:

1
2
3
4
5
6
7
8
def create_db(dli_client):
    try:
        db = dli_client.create_database('db_for_test')
    except DliException as e:
        print(e)
        return

    print(db)
  • The default database is a built-in database. You are not allowed to create a database named default.
  • For details about the dependencies and complete sample code, see Instructions.

Deleting a Database

DLI provides an API for deleting a database. The example code is as follows:

1
2
3
4
5
6
def delete_db(dli_client, db_name):
    try:
        dli_client.delete_database(db_name)
    except DliException as e:
        print(e)
        return
  • A database that contains tables cannot be deleted. To delete a database that contains tables, delete the tables first.
  • A deleted database cannot be restored. Therefore, exercise caution when deleting a database.
  • For details about the dependencies and complete sample code, see Instructions.

Querying All Databases

DLI provides an API for querying the database list. The example code is as follows:

1
2
3
4
5
6
7
8
9
def list_all_dbs(dli_client):
    try:
        dbs = dli_client.list_databases()
    except DliException as e:
        print(e)
        return

    for db in dbs:
        print(db)

For details about the dependencies and complete sample code, see Instructions.