NewSQL

1 min read


Okay ya guyss, balik lagi nih.. kali ini kita coba berkenalan dengan NewSQL ya..

NewSQL merupakan suatu database yang mengkombinasikan fungsi-fungsi pada RDBMS traditional seperti MySQL, Postgres dengan NoSQL seperti MongoDB, CassandraDB dll.

Jadi seperti yang dilihat pada tabel diatas kalau newsql ini melengkapi kekurangan dari type SQL yang sebelumnya..

Chocroach DB

Build what you dream Never worry about your database again.

install

curl https://binaries.cockroachdb.com/cockroach-v21.2.3.linux-amd64.tgz | tar -xz && sudo cp -i cockroach-v21.2.3.linux-amd64/cockroach /usr/local/bin/
mkdir -p /usr/local/lib/cockroach
cp -i cockroach-v21.2.3.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
cp -i cockroach-v21.2.3.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
which cockroach
cockroach demo
SELECT ST_IsValid(ST_MakePoint(1,2));

resultnya:

 st_isvalid
--------------
true
(1 row)

start-single-node

cockroach start-single-node --help

Local cluster (secure)

mkdir certs my-safe-directory
cockroach cert create-ca \
--certs-dir=certs \
--ca-key=my-safe-directory/ca.key
cockroach cert create-node \
localhost \
$(hostname) \
--certs-dir=certs \
--ca-key=my-safe-directory/ca.key
cockroach cert create-client \
root \
--certs-dir=certs \
--ca-key=my-safe-directory/ca.key
cockroach start \
--certs-dir=certs \
--store=node1 \
--listen-addr=localhost:26257 \
--http-addr=localhost:8080 \
--join=localhost:26257,localhost:26258,localhost:26259 \
--background

query:

CREATE DATABASE bank;
CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
INSERT INTO bank.accounts VALUES (1, 1000.50);
SELECT * FROM bank.accounts;

resutl:
id | balance
+----+---------+
   1 | 1000.50
(1 row)

\q
cockroach sql --certs-dir=certs --host=localhost:26258
SELECT * FROM bank.accounts;

result: 
id | balance
+----+---------+
   1 | 1000.50
(1 row)

Bima Sena

Leave a Reply

Your email address will not be published. Required fields are marked *