# Getting started with immudb Development

This guide provides developers with the first steps of using immudb from their application and from their favourite programming language:

  • Connect to the database
  • Insert and retrieve data

TIP

To learn how to develop for immudb with Python in a guided online environment, visit the immudb Playground at https://play.codenotary.com (opens new window)

# SDKs

In the most common scenario, you would perform write and read operations on the database talking to the server. In this case your application will be a client to immudb.

SDKs make it comfortable to talk to the server from your favourite language, without having to deal with details about how to talk to it.

The most well-known and recommended immudb SDK is written in Golang (opens new window), but there are other SDKs available, both maintainer by the internal team and by the community.

Language Maintainer Immdb version link Notes
go immudb team 1.2.1 link (opens new window)
python immudb team 1.2.1 link (opens new window) Verification is not working
JAVA immudb team 1.2.1 link (opens new window) Verification is not working
.NET immudb team 1.2.1 link (opens new window) Verification is not working
NODE immudb team 1.2.1 link (opens new window) Verification is not working
JS immudb team 1.2.1 link (opens new window) Verification is not working
ruby Community (Ankane (opens new window)) 1.2.1 link (opens new window) Verification is not working

For other unsupported programming languages, immugw provides a REST gateway that can be used to talk to the server via generic HTTP.

The immudb server manages the requests from the outside world to the store. In order to insert or retrieve data, you need to talk with the server.

SDK Architecture

# Connecting from your programming language

# Importing the SDK

In order to use the SDK, you need to download and import the libraries:

# Connection and authentication

The first step is to connect to the database, which listens by default in port 3322 and authenticate using the default user and password (immudb / immudb):

Note: You can change the server default options using environment variables, flags or the immudb.toml configuration file.

# Tamperproof read and write

You can write with built-in cryptographic verification. The client implements the mathematical validations, while your application uses a traditional read or write function.

# SQL Operations with the Go SDK

In order to use SQL from the Go SDK, you create a immudb client and login to the server like usual. First make sure you import:

"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/client"

Then you can create the client and open a new session to the database:

import (
"log"
"context"
immudb "github.com/codenotary/immudb/pkg/client"
)

c := immudb.NewClient()
err := c.OpenSession(context.TODO(), []byte(`immudb`), []byte(`immudb`), "defaultdb")
if err != nil {
    log.Fatal(err)
}

defer c.CloseSession(context.TODO())

// do amazing stuff

To perform SQL statements, use the SQLExec function, which takes a SQLExecRequest with a SQL operation:

 _, err = c.SQLExec(ctx, `
  BEGIN TRANSACTION
          CREATE TABLE people(id INTEGER, name VARCHAR, salary INTEGER, PRIMARY KEY id);
          CREATE INDEX ON people(name)
  COMMIT
 `, map[string]interface{}{})
  if err != nil {
  log.Fatal(err)
 }

This is also how you perform inserts:

_, err = c.SQLExec(ctx, "UPSERT INTO people(id, name, salary) VALUES (@id, @name, @salary);", map[string]interface{}{"id": 1, "name": "Joe", "salary": 1000})
if err != nil {
    log.Fatal(err)
}

Once you have data in the database, you can use the SQLQuery method of the client to query.

Both SQLQuery and SQLExec allows named parameters. Just encode them as @param and pass map[string]{}interface as values:

res, err := c.SQLQuery(ctx, "SELECT t.id as d,t.name FROM (people AS t) WHERE id <= 3 AND name = @name", map[string]interface{}{"name": "Joe"}, true)
if err != nil {
    log.Fatal(err)
}

res is of the type *schema.SQLQueryResult. In order to iterate over the results, you iterate over res.Rows. On each iteration, the row r will have a member Values, which you can iterate to get each column.

for _, r := range res.Rows {
    for _, v := range r.Values {
        log.Printf("%s\n", schema.RenderValue(v.Value))
    }
}

# Additional resources