Skip to content

Org, Team & App Databases

Every app gets one database per owner. By default, bzr.collection() uses the database of the logged-in user. A context gives you access to another owner’s database:

  • another user’s database (with their permission)
  • an org’s or a team’s database, shared by its members
  • the app’s own database, managed by the app’s developers
const ctx = await bzr.createContext({ ownerId: "owner-id" });
const tasks = ctx.collection("tasks");
await tasks.getAll();

A context has the same collection(), collections, permissions, and files APIs as bzr, scoped to that owner’s database.

Contexts are cheap: they share one connection per server. When you’re done with one that doesn’t last as long as the page, e.g. after reading a profile the user visited, close it. This ends its subscriptions and lets the server close the owner’s database:

await ctx.close();
  • User databases: the user always has full access. Others need a permission.
  • Org, team, and app databases: nobody has implicit access, not even admins. All access goes through permissions.

When an org, team, or app database is created, it gets default permissions. The owning team can list collections, read permissions, and use files. Its admins (GranteeType.ADMINS) can also create and drop collections and manage permissions. There are no default permissions on your collections. An admin creates them, e.g. when a collection is created:

import { GranteeType, PermissionType } from "@bzr/bazaar";
const orgId = "example-org-id";
const org = await bzr.createContext({ ownerId: orgId });
const tasks = org.collection("tasks", {
onCreate: async () => {
await org.permissions.create({
collectionName: "tasks",
granteeType: GranteeType.ORG,
granteeId: orgId,
types: [
PermissionType.READ,
PermissionType.INSERT,
PermissionType.UPDATE,
PermissionType.DELETE,
],
});
},
});

If members lose access because default permissions were deleted, an org admin can restore them on the org’s page in the dashboard.

Use the org’s ID as ownerId. The org ID is shown on the org’s page in the dashboard. Only members of the org (or team) can create its database. Once it exists, others can access it with a permission.

Permissions in any database can be granted to an org or a team with GranteeType.ORG or GranteeType.TEAM. See grantees.

Each app has a database owned by the app itself. Use it for data that belongs to the app rather than to a user, e.g. public content or settings.

const app = await bzr.appContext();

appContext() is a shortcut for createContext({ ownerId: appId }). The app’s owner (the developer who created it, or the admins of the org that owns it) has the default permissions. Other users only get what the owner grants, for example read access for everyone:

const app = await bzr.appContext();
await app.permissions.create({
collectionName: "announcements",
granteeType: GranteeType.ANY,
types: [PermissionType.READ],
});

Only the app’s owner can create the app database. Its storage comes from the owner’s plan: Creator and Business plans include app storage. On other plans, the app database has no storage for data.