orbitdb/docs/GETTING_STARTED.md
Hayden Young 5ab0bcdbf5
Docs (#66)
* docs: Access controllers.

* test: Re-open an existing db using its address.

* docs: Simple db interaction.

* docs: Basic Identities.

* docs: Storage.

* docs: Implementing a custom database.

* docs: Example OrbitDB AC.

* docs: Use identity id when customizing access.

* docs: canAppend.

* docs: Graphically describe log joining.

* docs: Update db types.

* docs: Sync-ing.

* docs: Reverse flow arrows.

* docs: Logical clock.

* docs: DB address and manifest.

* docs: Move ops description to db.

* docs: CRDT.

* docs: Peer discovery, connecting ipfs nodes, orbitdb replication.

* docs: Change file name case to match other documentation solutions (e.g. IPFS/libp2p).

* docs: Links to CRDT papers.

* docs: A getting started to get up and running quickly.

* docs: Move replication to own readme.

* docs: Links to various js-libp2p connection config.

* docs: Examples for connecting two node servers.

* docs: Server to browser connection.

* docs: Replication how-to.

* docs: Remove SYNC.

* docs: Simplify oplog discussion.

* docs: Connecting to IPFS in the browser.

* docs: Topics moved to separate docs.
2023-05-05 00:33:36 +08:00

1.5 KiB

Getting Started

This guide will help you get up and running with a simple OrbitDB database that you can replicate across multiple peers.

install

Install OrbitDB:

npm i orbit-db

You will also need IPFS for replication:

npm i ipfs-core

Creating a simple database

To create a database, launch an instance of OrbitDB call the open function with a unique database name:

const ipfs = await IPFS.create()
const orbitdb = await OrbitDB({ ipfs })
const db = await orbitdb.open('my-db')

Once opened, your new database will reside on the system it was created on.

Without a type, OrbitDB defaults to a database type of 'events'. To change the database type, pass a type with a valid database type:

const type = 'documents'
const ipfs = await IPFS.create()
const orbitdb = await OrbitDB({ ipfs })
const db = await orbitdb.open('my-db', { type })

Replicating a database

A database created on one peer can be replicated on another by opening the database by its address rather than by its name:

const address = '/orbitdb/zdpuAzzxCWEzRffxFrxNNVkcVFbkmA1EQdpZJJPc3wpjojkAT'
const ipfs = await IPFS.create()
const orbitdb = await OrbitDB({ ipfs })
const db = await db.open(address)

IPFS is required for carrying out the underlying replication.

More information about replication is available in the Replication documentation.

Further Reading

The Databases documentation covers replication and data entry in more detail.