GO API: Database
In this post, we will create database for our GOLANG API project. For this series for tutorial we are using cockroachDB
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
In this post, we will create database for our GOLANG API project. For this series for tutorial we are using cockroachDB
CockroachDb
If you have not installed cockroachDb yet. Please follow this post Install CockroachDB.
Create Database
Start a CockroachDB node and access cockroachDB client shell. If you are not familiar with this you can follow this post CockroachDB Client Command. Once you have access to cockroachdb client create database
- Create a User
- Create database
- Create table
- Grant All access to User
Create User
Create cockroachDB user
CREATE USER USERNAME;
Create Database
CREATE DATABASE students;
Create Table
use students;
CREATE TABLE students.student_tlb (
roll_number INT PRIMARY KEY,
name STRING,
batch STRING,
branch STRING
);
Grant Access
GRANT ALL ON TABLE students.* TO USERNAME;
Extra
Let's insert some dummy data into student_tlb table. INSERT INTO students.student_tlb VALUES
(0001, 'Sophia', '2017', 'Computer Science'),
(0002, 'Olivia', '2014', 'Computer Science'),
(0003, 'William', '2018', 'Computer Science'),
(0004, 'Mason', '2016', 'Computer Science'),
(0005, 'Emma', '2013', 'Computer Science');
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment