Skip to content

Commit

Permalink
Merge pull request #422 from codenotary/chore_update_doc
Browse files Browse the repository at this point in the history
Chore update doc
  • Loading branch information
jeroiraz authored Oct 19, 2023
2 parents b7c6cfd + dc8651f commit 073f7e6
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 14 deletions.
17 changes: 16 additions & 1 deletion src/.vuepress/sidebar_master.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,29 @@ export default version => {
developSQL.children.push(`${version}/develop/sql/datatypes`);
developSQL.children.push(`${version}/develop/sql/tablescreate`);
developSQL.children.push(`${version}/develop/sql/tablesalter`);
developSQL.children.push(`${version}/develop/sql/tablesdrop`);
developSQL.children.push(`${version}/develop/sql/insertupdate`);
developSQL.children.push(`${version}/develop/sql/indexes`);
developSQL.children.push(`${version}/develop/sql/querying`);
developSQL.children.push(`${version}/develop/sql/catalog`);
developSQL.children.push(`${version}/develop/sql/sqlstdlib`);
developSQL.children.push(`${version}/develop/sql/pg`);

/* DEVELOP SQL SECTION END */

/* DEVELOP DOCUMENT SECTION START */
let developDocument = {
title: 'Develop with Document',
collapsable: true,
children: [
]
};

developDocument.children.push(`${version}/develop/document/datamodel`);
developDocument.children.push(`${version}/develop/document/api`);

/* DEVELOP DOCUMENT SECTION END */

/* EMBEDDED SECTION START */
let embedded = {
title: 'Embedded',
Expand Down Expand Up @@ -161,6 +175,7 @@ export default version => {
sidebar.push(management);
sidebar.push(developKV);
sidebar.push(developSQL);
sidebar.push(developDocument);
sidebar.push(embedded);
sidebar.push(releaseNotes);

Expand Down
2 changes: 1 addition & 1 deletion src/master/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Welcome to the immudb documentation. Great to see you here!

immudb is a database written in Go, but unlike other databases, it is immutable: history is preserved and can't be changed without clients noticing.

immudb can be used both as a key-value store, or as a relational database (SQL).
immudb can operate as a key-value, relational (SQL) or document database, making it a truly no-SQL database.

immudb can be run as full database server with replicas or easily embedded as a lightweight database into application.

Expand Down
259 changes: 259 additions & 0 deletions src/master/develop/document/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
# API

::: tip
By default, Swagger UI is enabled and can be accessed at `http://localhost:8080/api/docs/`
:::

<WrappedSection>

## Authentication

A session must be active in order for you to be able to access collection and document endpoints.

### Open session

In the following script, the default credentials are used to open a session in the defaultdb database.

A sessionID is assigned by immudb, and this value must be included in all subsequent requests.

```bash
sessionid=$(
curl -X 'POST' \
'http://localhost:8080/api/v2/authorization/session/open' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"username": "immudb",
"password":"immudb",
"database":"defaultdb"
}' | jq -r .sessionID)
```


### Close session

Although immudb automatically closes inactive sessions, it is a good practice to explicitly close sessions when they are not needed anymore in order to free up resources immediately.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/authorization/session/close' -H "sessionID: $sessionid"
```

</WrappedSection>

<WrappedSection>

## Collections

Collections allow you to store and manage related documents together, making it easier to search and retrieve relevant data.

### Create collection

Any json object can be stored in a collection, but declared fields enable indexes to be created.

Here is the script that creates a collection with two fields of type `STRING` and a non-unique index over one of them.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection' \
-H "sessionID: $sessionid" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"fields": [
{"name": "name", "type": "STRING"},
{"name": "surname", "type": "STRING"}
],
"indexes": [
{"fields": ["name"], "unique": "false"}
]
}'
```

### Delete collection

It is possible to delete collections, and the physical removal of any declared index will be carried out. The raw data in the transaction commit log have not been altered, but this operation cannot be reversed.

```bash
curl -X 'DELETE' \
'http://localhost:8080/api/v2/collection/mycollection' \
-H "sessionID: $sessionid"
```

</WrappedSection>

<WrappedSection>

## Indexes

Collections allow you to store and manage related documents together, making it easier to search and retrieve relevant data.

### Create index

It is possible to create indexes over the declared fields in the collection.

Creating non-unique indexes is possible at any time, while creating unique ones is only possible when no documents have been stored.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection/index' \
-H 'accept: application/json' \
-H "sessionID: $sessionid" \
-H 'Content-Type: application/json' \
-d '{
"fields": [
"surname"
]
}'
```

### Delete index

It is possible to delete collections, and the physical removal of any declared index will be carried out. The raw data in the transaction commit log have not been altered, but this operation cannot be reversed.

```bash
curl -X 'DELETE' \
'http://localhost:8080/api/v2/collection/mycollection/index?fields=surname' \
-H "sessionID: $sessionid"
```

</WrappedSection>

<WrappedSection>

## Documents

Collections allow you to store and manage related documents together, making it easier to search and retrieve relevant data.

### Insert document

Single or multiple documents can be inserted in a single request

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection/documents' \
-H "sessionID: $sessionid" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"documents": [
{"name":"John", "surname":"Doe"},
{"name":"Jane", "surname":"Smith"}
]
}'
```

### Search documents

It is possible to delete collections, and the physical removal of any declared index will be carried out. The raw data in the transaction commit log have not been altered, but this operation cannot be reversed.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection/documents/search' \
-H "sessionID: $sessionid" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": {
"expressions": [
{
"fieldComparisons": [
{
"field": "name",
"operator": "EQ",
"value": "John"
}
]
}
]
},
"page": 1,
"pageSize": 10
}'
```

### Replace documents

A single or multiple documents can be atomically replaced.

```bash
curl -X 'PUT' \
'http://localhost:8080/api/v2/collection/mycollection/documents/replace' \
-H 'accept: application/json' \
-H "sessionID: $sessionid" \
-H 'Content-Type: application/json' \
-d '{
"query": {
"expressions": [
{
"fieldComparisons": [
{
"field": "_id",
"operator": "EQ",
"value": "6530f0fa000000000000001f86853b05"
}
]
}
],
"limit": 1
},
"document": {
"first_name": "John",
"last_name": "Doe",
"age": 40
}
}'
```

### Delete documents

Documents can be deleted. A document audit preserves document history and allows for retrieval of all revisions, even deleted ones.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection/documents/delete' \
-H 'accept: application/json' \
-H "sessionID: $sessionid" \
-H 'Content-Type: application/json' \
-d '{
"query": {
"expressions": [
{
"fieldComparisons": [
{
"field": "first_name",
"operator": "EQ",
"value": "John"
},
{
"field": "last_name",
"operator": "EQ",
"value": "Doe"
}
]
}
],
"limit": 1
}
}'
```

### Audit documents

Document revisions can be retrieved through a document audit. In auditing, all revisions are tracked and retrievable, even those that have been deleted.

In order to audit a document, it is necessary to know its unique identifier, which can be obtained by inserting or querying the document.

```bash
curl -X 'POST' \
'http://localhost:8080/api/v2/collection/mycollection/document/6530f0fa000000000000001f86853b05/audit' \
-H 'accept: application/json' \
-H "sessionID: $sessionid" \
-H 'Content-Type: application/json' \
-d '{
"page": 1,
"pageSize": 10
}'
```

</WrappedSection>
16 changes: 16 additions & 0 deletions src/master/develop/document/datamodel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Data Model

::: tip
By default, Swagger UI is enabled and can be accessed at `http://localhost:8080/api/docs/`
:::

<WrappedSection>

### Collection

A collection is a container for documents of a similar type. Each database can have one or many collections. The documents within a collection can have various structures, but they must all be JSON files. Collections allow you to store and manage related documents together, making it easier to search and retrieve relevant data.

### Documents
Documents are JSON files containing structured data that are stored within a collection. Each document can have multiple versions, allowing you to track changes and maintain a history of modifications.

</WrappedSection>
2 changes: 2 additions & 0 deletions src/master/develop/sql/datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
| VARCHAR | UTF8-encoded text | Maximum number of bytes in the UTF-8 encoded representation of the string |
| BLOB | sequence of bytes | Maximum number of bytes in the sequence |
| TIMESTAMP | datetime value with microsecond precision | - |
| FLOAT | IEEE-754 64-bit floating-point number | - |
| UUID | Universally Unique Identifier (UUID), 128-bit value | - |

<br/><br/>

Expand Down
18 changes: 18 additions & 0 deletions src/master/develop/sql/indexes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Indexes

::: tip
If you create lots of indexes, you may want to adjust default settings to reduce your memory footprint.

Indexing parameters, including cache-size, flush-thresholds, and max-active-snapshots, can be lowered as needed, but take into account more IO reads and writes, which may lead to poor indexing performance.
:::

<WrappedSection>

immudb indexes can be used for a quick search of rows
Expand Down Expand Up @@ -49,4 +55,16 @@ This includes a use case where the table is not empty which can be used to simpl
Note: If the index already exists, it is not compared against the provided index definition neither it is
updated to match it.

</WrappedSection>

<WrappedSection>

### DROP INDEX

An index can be physically deleted. Table data is not deleted and can be queried using either the primary index or any other declared index. Non-unique indexes can be created at any time.

```sql
DROP INDEX ON customers(surname);
```

</WrappedSection>
Loading

0 comments on commit 073f7e6

Please sign in to comment.