This documentation was created easily with our tool LazyDoc ! 🚀 Try it for free now !

LazyDB

Getting started

getting started with LazyDB is really easy!

Introduction and requirements

Before you start, keep in mind that LazyDB alpha should NOT be used in production!


To use LazyDB you only need a LazyDB alpha server.

Quickstart

Before you can use LazyDB, you need to initilalize.

Quickstart

javascript

expand_more
content_paste

1

const db = new Database("alpha.lazydb.com", your_port);

Authentication

Authenticate your users

Register

Registering new users in LazyDB is really simple, you only need to call the register function and specify the email, password, username, and optionally a full_name.

Register

javascript

expand_more
content_paste

1

db.register("email", "password", "username", "full_name").then(() => {

2

	console.log("register done!");

3

}).catch(error => {

4

	console.error(error);

5

})

Connect

To connect a user, simply use the connect function with email and password params. Once the user is logged in the promise will resolve, if an error occurs the promise will throw an error.


User users can only have 1 active connection, if the user is already online, connect will throw an error.

Connect

javascript

expand_more
content_paste

1

db.connect("email", "password").then(userData => {

2

	console.log("Connected with uid : ", userData.id);

3

}).catch(error => {

4

	console.error(error);

5

});

Edit password

Modify a user password

Edit password gives you the ability to update a user's password as an admin or lets your user edit his own password.

Edit password

Javascript

expand_more
content_paste

1

db.edit_password(new_password, uid);

Get user status

Check if a user is online

Get user status to see if a user is online. You can also use on update to watch when the user status change in real-time!

Get user status

Javascript

expand_more
content_paste

1

db.get("users/uid/c").then(status => {

2

	if(status === true){

3

    	console.log("user online");

4

    }else{

5

    	console.log("user offline");

6

    }

7

}).catch(error => {

8

	console.error(error);

9

});

Retrieving data

Discover how you can get data on LazyDB

Get

The simplest way to get data

The get command is the simplest way to get data from your LazyDB server. You can specify the depth you want, each depth will get the data of one more sub-child.


Get

javascript

expand_more
content_paste

1

const depth = 5;

2

db.get("path/to/your/data", depth).then(data => {

3

	console.log(data);

4

}).catch(error => {

5

	console.error(error);

6

})

Sort

Sort is a more complex command than the get command, it enables you to sort the data you want to get, and for example, get all 10 first in ascending order.

Sort

Javascript

expand_more
content_paste

1

db.sort("path/to/your/data", {char: "_", num: 1}, {count: 10, start: 0, order: "asc"}, "asc").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Keys

Get an array of all the keys of the given path, without getting all the data.

Keys

javascript

expand_more
content_paste

1

db.keys("path/to/your/data", "keys").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Editing data

Discover how you can create, delete and update data in LazyDB

Create

Create is used to create data, it will return an error if the path already exists.

Create

javascript

expand_more
content_paste

1

const data = {};

2

// data can be anything, object, string, number or bool

3

db.create("path/to/data", data).then(() => {

4

	console.log("Data created!");

5

}).catch(error => {

6

	console.error(error);

7

});

Update

The update command is used to update data at a given path.

The update will fail if the given path does not exist.

Update

Javascript

expand_more
content_paste

1

db.update("path/to/your/data", "data").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Delete

Delete data at the given path.

Delete

javascript

expand_more
content_paste

1

db.delete("path/to/your/data").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Realtime updates

Add realtime features to any app!

On

The on command is used to watch real-time events on a specific path.

On

javascript

expand_more
content_paste

1

db.on("command", "path/to/your/data").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Watch

The watch command is used to watch real-time changes to the children of the specified path.

Watch

javascript

expand_more
content_paste

1

db.watch("command", "path/to/your/data").then(data => {

2

	console.log(data);

3

}).catch(error => {

4

	console.error(error);

5

})

Groups

Give your users the ability to make groups

Create

make a new group

Creating a group is simple.

Create

Javascript

expand_more
content_paste

1

db.create("group/group_name").then(gid => {

2

	console.log("Group created with id : " + gid);

3

}).catch(error => {

4

	console.error(error);

5

});

Join

join a group you have been invited in

Join a group you have been invited to.

Join

Javascript

expand_more
content_paste

1

db.join("group_id").then(() => {

2

	console.log("Group joined!");

3

}).catch(error => {

4

	console.error(error);

5

});

Invite

invite someone to join your group

Invite someone to join a group.

Invite

Javascript

expand_more
content_paste

1

db.invite("group_id", "user_id", "role").then(() => {

2

	console.log("user has been invited!");

3

}).catch(error => {

4

	console.error(error);

5

});

Leave

leave a group

Leave the group.

Leave

Javascript

expand_more
content_paste

1

db.leave("group_id").then(() => {

2

	console.log("done");

3

}).catch(error => {

4

	console.error(error);

5

});

Securing paths

Learn how security works in LazyDB

Public

Make your data public

A public path can be accessed by any registered users, but they can't update it or create sub-paths.


To give the public access to the given path, you only need to include the keyword "public" in the path. For example everything below "my/folder/public", will be public.

Private

Make a user data private

A private path can be accessed by admins or the owner of the path, they can update or get it but can't create sub-paths.


To give the public access to the given path, you only need to include the keyword "private" in the path. For example, everything below "my/folder/uid/private", will be private and the owner will be the user with id uid.

Stats

Get more infos about LazyDB

Online users

get realtime update on your realtime user count

You can get the currently online users like any data in LazyDB, using the "limit/online_users" path. You can also use the command on to get noticed when the counter updates.

Online users

Javascript

expand_more
content_paste

1

db.get("limit/online_users").then(data => {

2

	console.log(data.current + " online users, max online users : " + data.max);

3

}).catch(error => {

4

	console.error(error);

5

});