Database
Last updated
Was this helpful?
Last updated
Was this helpful?
DoltHub provides a database API for fetching and creating data on your database. You can create a database, create a pull request, create a pull request comment, and merge a pull request through these APIs.
Please make sure to send your requests to https://www.dolthub.com
instead of https://dolthub.com
.
Here's an example of how to create a new database called museum-collections
under the organization dolthub
using an authorization token.
Creating a database requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
Here is an example of opening a pull request on the museum-collections
database with data from the Los Angeles County Museum of Art. This data was added to the lacma
branch on a fork database, whose owner
is liuliu
, we would like to eventually merge lacma
branch into the main
branch using an authorization token.
Include this header
in your request.
This API allows you to retrieve the details of a specific pull request in the museum-collections
database. In this example, we will retrieve the details of pull request #1.
Include this header
in your request.
This API allows you to update a pull request by providing the fields you want to update in the request body. You can update the title, description, and state (only closing a pull request is supported).
Here's an example of how to update pull request #1 on the museum-collections database. In this example, we will set a new title, description, and close the pull request.
Here is an example of listing pull requests for the museum-collections
database using an authorization token. The response of pull request list is paginated, so you need to use the next page token included in the response to retrieve the following pages of pull requests.
Include this header
in your request.
Here is an example of adding a pull request comment using an authorization token.
Include this header
in your request.
Here is an example of merging a pull request #66
on a database museum-collections
using an authorization token. Note that the merge operation is asynchronous and creates an operation that can be polled to get the result.
To poll the operation and check its status, you can use the operationName
in the returned response of the merge request to query the API. Once the operation is complete, the response will contain a job_id
field indicating the job that's running the merge, as well as other information such as the database_owner
, database_name
, and pull_id
.
Keep in mind that the time it takes for the merge operation to complete can vary depending on the size of the pull request and the complexity of the changes being merged.
Include this header
in your request with the API token you created.
Then use GET
to poll the operation to check if the merge operation is done.
Here is an example of uploading a file lacma.csv
to create a table lacma
on a database museum-collections
using an authorization token. Note that the file import operation is asynchronous and creates an operation that can be polled to get the result.
To poll the operation and check its status, you can use the operationName
in the returned response of the file upload post to query the API. Once the operation is complete, the response will contain a job_id
field indicating the job that's running the file import as well as the id of the pull request that's created when the import job is completed.
Keep in mind that the time it takes for the import operation to complete can vary depending on the size of the file and the complexity of the changes being applied to the database. The file size limit is 100 MB.
Include this header
in your request with the API token you created.
To upload the file, include two fields in the request body, file
and params
, the file
should be type of Blob
, and params
should be a JSON object.
Then use GET
to poll the operation to check if the import operation is done.
Here is an example of uploading a CSV file to create a table through this api endpoint in Javascript, you can reference the dolt table import
documentation for additional information.:
Please make sure to send your requests to https://www.dolthub.com/api/v1alpha1/{owner}/{database}/upload
instead of https://www.dolthub.com/api/v1alpha1/{owner}/{database}/upload/
, do not need the last /
.
And an example of polling the job status in Javascript:
Here's an example of how to create a new branch in database museum-collections
under the organization dolthub
using an authorization token.
Creating a branch requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
Here's an example of how to list branches in the database museum-collections
under the organization dolthub
using an authorization token.
Listing branches requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
Here's an example of how to create a new tag in the database museum-collections
under the organization dolthub
using an authorization token.
Creating a tag requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
Here's an example of how to list tags in the database museum-collections
under the organization dolthub
using an authorization token.
Listing tags requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
Here's an example of how to create a new release in the database museum-collections
under the organization dolthub
using an authorization token.
Creating a release requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
{% swagger src="../../../.gitbook/assets/dolthub-api/createRelease.json" path="/{owner}/{database}/releases" method="post" % } createRelease.json
Here's an example of how to list releases in the database museum-collections
under the organization dolthub
using an authorization token.
Listing releases requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
DoltHub provides support for asynchronous operations, including merging, SQL writes, and file importing. When you execute one of these operations from the API, you will get an operation name that you can poll using another endpoint to check the operation status and other information.
This API endpoint lets you monitor the status of all the operations you started in one place without needing to poll the endpoints for singular operations. These operations have error
and metadata
fields which contain useful information for troubleshooting and debugging.
For example, if you have executed a few SQL write queries using that API endpoint, you can list those operations using the operationType
query parameter to filter for SqlWrite
operations. The metadata
will show the query executed, database and branch that the query ran on, as well as any syntax or other errors you may have encountered.
Here's an example of how to list SqlWrite
operations initiated by user liuliu
using an authorization token.
Listing operations requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
DoltHub performs certain asynchronous operations through job execution, including merging, importing, SQL reading, and migrating. When these operations are initiated via the API, you receive an operation name that includes the job ID.
This API endpoint lets you monitor the status of jobs started in a specific database.
Here is an example of how to list all the jobs on a database museum-collections
using an authorization token.
Listing jobs requires authentication, so you must include this authorization header in your request. See the Authentication section for more details.
This API allows you to create a new Dolt database.
/api/v1alpha1/database
A description of the database.
Records from museums around the world.
The name of the owner of the database.
dolthub
The name of the repository for the database.
museum-collections
The visibility of the database (public or private).
public
/{owner}//{database}/pulls/{pull_id}/comments
Owner of the database
dolthub
database name
museum-collections
Pull request ID
66
Comment to be added to the pull request
The pull request looks good!
List pull requests
/{owner}//{database}/pulls
The name of the database owner.
dolthub
The name of the database.
museum-collections
The pageToken to get the next page of results
AWE2Nm9uMWQ23FSQ7oRTbCXYTLLvNDhNs5hIFebQFI66FW-SYXGSlh3XcUQ8zmtLQ00QgD0X5FZr5ZTAhvT2FfRrGog7OuUno9wdTIXFQpkkX0opYoJL6Vrn2emlXkMBTiZYMqChyhR92_Yxd58B0w5nMrfXFf8v7xfAkN46hw
Filter pulls by state, can be Open, Closed, or Merged.
Open
Filter pulls by review status, can be Approved, AssignedReviewer, Rejected or Reviewed
Approved
Search by pull request title or author name.
test
Updates a pull request by ID, including its title, description, and sets its state to be 'closed'.
/{owner}//{database}/pulls/{pull_id}
The name of the database owner.
dolthub
The name of the database.
museum-collections
ID of the pull request to update.
1
The updated title of the pull request.
Added new data
The updated description of the pull request.
Added new data from LACMA museum.
The updated state of the pull request (can only update to 'closed')
closed
This API allows you to create a new pull request.
/{owner}//{database}/pulls
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
The title of the pull request.
LACMA data
The description of the pull request.
Records from the Los Angeles County of Museum.
The name of the owner of the source branch.
liuliu
The name of the database containing the source branch.
museum-collections
The name of the source branch.
lacma
The name of the owner of the destination branch.
dolthub
The name of the database containing the destination branch.
museum-collections
The name of the destination branch.
main
Get information about a specific pull request.
/{owner}//{database}/pulls/{pull_id}
The name of the database owner.
dolthub
The name of the database.
museum-collections
ID of the pull request
1
Poll the operation to check if the file import operation is done
/{owner}//{database}/upload
The owner of the database
dolthub
The database name
museum-collections
The name of the branch to upload the file to.
main
The operation name to check
repositoryOwners/dolthub/repositories/museum-collections/jobs/b09a9221-9dcb-4a15-9ca8-a64656946f12
This API endpoint allows you to list all releases in your database.
/{owner}//{database}/releases
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
The next page token.
1234567890
This endpoint allows you to upload a file to DoltHub to create, update, overwrite, or replace a table.
/{owner}//{database}/upload
The name of the database owner.
dolthub
The name of the database.
museum-collections
The file to be uploaded.
This endpoint merges a pull request into the destination branch.
/{owner}//{database}/pulls/{pull_id}/merge
The name of the database owner.
dolthub
The name of the database.
museum-collections
The ID of the pull request to merge.
66
This API endpoint allows you to list all tags in your database.
/{owner}//{database}/tags
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
Poll the operation to check if the merge operation is done
/{owner}//{database}/pulls/{pull_id}/merge
The owner of the database
dolthub
The database name
museum-collections
The ID of the pull request
66
The operation name to check
repositoryOwners/dolthub/repositories/museum-collections/jobs/b09a9221-9dcb-4a15-9ca8-a64656946f12
This API endpoint allows you to create a new tag in your database.
/{owner}//{database}/tags
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
The name of the tag.
v1
The description of the tag.
First version of the database
The type of revision, can be either 'branch', 'ref' or 'commit'.
branch
The name of revision. If revisionType is 'branch', this is the name of the base branch. If revisionType is 'commit', this is the commit hash.
main
This API endpoint allows you to list all branches in your database.
/{owner}//{database}/branches
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
This API endpoint allows you to list all jobs in your database.
/{owner}//{database}/jobs
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
This API endpoint allows you to list all operations that are created by the user.
/users/{username}/operations
The name of the user who initiated the operations. This user's name must match the user associated with the api token.
liuliu
Specific type of operation for this query. Supported operation types are SqlWrite, SqlRead, Import, Merge, Migrate.
SqlWrite
Token for the next page of results
AWE2Nm9uMWQ26pQQpqLNLXu7a60647lpiZoDFrf5WDGHo68XNC-rfr068rymbEdUHCXidRxx7_fwGBMSzQi6C_D50NcJFXm0BwRnGmmHEL4T4xxkWoX3sL5mKD-PuMRuxeHPsR0NB5Rzi70jGzblVlfBTIHPJ20c630pNLrI_spxH0tYTzMnQ4uPpr3ub9P50FEH9i4Au0gUkmvj8NUibbGWi-R1AJYplEPr=
This API endpoint allows you to create a new branch in your database.
/{owner}//{database}/branches
The name of the owner of the database.
dolthub
The name of the database.
museum-collections
The type of revision, can be either 'branch', 'ref' or 'commit'.
branch
The name of revision. If revisionType is 'branch', this is the name of the base branch. If revisionType is 'commit', this is the commit hash.
main
The name of the new branch.
feature-branch