Before you begin
- .
- Start up a or local cluster.
- Choose the instructions that correspond to whether your cluster is secure or insecure:
The
--insecure flag used in this tutorial is intended for non-production testing only. To run CockroachDB in production, use a secure cluster instead.Step 1. Create the maxroach user and bank database
Start the :
maxroach user and bank database:
maxroach user the necessary permissions:
Step 2. Generate a certificate for the maxroach user
Create a certificate and key for the maxroach user by running the following command:
maxroach as the user.
Step 3. Run the Go code
The sample code shown below uses upper/db to map Go-specific objects to SQL operations. Specifically, the code:- Creates the
accountstable, if it does not already exist. - Deletes any existing rows in the
accountstable. - Inserts two rows into the
accountstable. - Prints the rows in the
accountstable to the terminal. - Deletes the first row in the
accountstable. - Updates the rows in the
accountstable within an explicit . - Prints the rows in the
accountstable to the terminal once more.
crdbForceRetry()). Upper/db’s CockroachDB adapter when transaction errors are thrown. As a result, this function forces a transaction retry.
To run the code, copy the sample above, or download it directly.
Step 1. Create the maxroach user and bank database
Start the :
maxroach user and bank database:
maxroach user the necessary permissions:
Step 2. Run the Go code
The sample code shown below uses upper/db to map Go-specific objects to SQL operations. Specifically, the code:- Creates the
accountstable, if it does not already exist. - Deletes any existing rows in the
accountstable. - Inserts two rows into the
accountstable. - Prints the rows in the
accountstable to the terminal. - Deletes the first row in the
accountstable. - Updates the rows in the
accountstable within an explicit . - Prints the rows in the
accountstable to the terminal once more.
crdbForceRetry()). Upper/db’s CockroachDB adapter when transaction errors are thrown. As a result, this function forces a transaction retry.
Copy the code or download it directly.
To clone a version of the code below that connects to insecure clusters, run the following command:
git clone https://github.com/cockroachlabs/hello-world-go-upperdb/
Change to the directory where you cloned the repo and get the dependencies with go mod init:

