Skip to main content
Home

A Deno database client for Google Cloud Firestore.

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
64%
Published
a year ago (3.6.4)

deno module deno compatibility GitHub

X-Database

A Deno database client for Google Cloud Firestore.

Example

import Database from 'https://deno.land/x/xdatabase/src/mod.ts';

const database = new Database();

database.credential('application');
database.project('google-cloud-project-id');

const id = crypto.randomUUID();

const user = await database.create('user', {
    id,
    age: 20,
    phone: null,
    active: true,
    lastName: 'bar',
    firstName: 'foo',
}).identifier(id).end();

console.log(user);

const users = await database
    .search('user')
    .equal({ firstName: 'foo' })
    .limit(10).end();

console.log(user);

Auth

It is recommended to use the 'application' String option this will use the Application Default Credential and will fallback to trying to use the Google Cloud service instance account credentials. You can initialize the Application Default Credential using this command gcloud auth application-default login. Alternatively you can pass a ServiceAccountCredentials key Object, ApplicationDefaultCredentials key Object, or the 'meta' String. The option to manually use 'meta' is nice for production because the only deno permission you should need is network.

  • 'meta'
    • http://metadata.google.internal
  • 'application' Deno permissions read
    • Windows: %APPDATA%\gcloud\application_default_credentials.json
    • Linux/Mac: $HOME/.config/gcloud/application_default_credentials.json

API

id(id: string): this

The database id default is (default)

project(project: string): this

The GCP project name.

credential(credential: 'meta' | 'application' | ServiceAccountCredentials | ApplicationDefaultCredentials): this

  • meta
  • application
  • ServiceAccountCredentials
  • ApplicationDefaultCredentials

search(collection: string)

const users = await database.search('user').equal({ id: '1' }).end();

view(collection: string)

const user = await database.view('user').equal({ id: '1' }).end();

remove(collection: string)

const user = await database.remove('user').identifier('1').end();

create(collection: string, data: Data)

const user = await database.create('user', {
    id: '1',
    name: 'foo bar',
    age: 42,
}).identifier('1').end();

update(collection: string, data: Data)

const user = await database.update('user', { age: 69 }).equal({ id: '1' })
    .end();

commit(collection: string, data: Data)

const user = await database.commit('user').equal({ id: '1' }).increment({
    age: 1,
}).end();

Options

// All Except Search:
identifier(string)

// All Except Set: Property starts with filter
startsWith(Array<string>)

// All Except Set:
in(Array<string>)

// All Except Set:
notIn(Array<string>)

// All Except Set: default
equal(Array<string>)

// All Except Set:
notEqual(Array<string>)

// All Except Set:
lessThan(Array<string>)

// All Except Set:
lessThanOrEqual(Array<string>)

// All Except Set:
arrayContains(Array<string>)

// All Except Set:
arrayContainsAny(Array<string>)

// All Except Set:
greaterThan(Array<string>;

// All Except Set:
greaterThanOrEqual(Array<string>)

// Search: orders results by property name/s
ascending(Array<string>)
descending(Array<string>)

// Search:
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.start_at
start(Array<Record<string, Data>>)

// Search:
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.end_at
end(Array<Record<string, Data>>)

// Search: The maximum number of results to return.
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.limit
limit(number)

// Search: The number of results to skip.
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.offset
offset(number)

// Set: property name/s to increment
// https://firebase.google.com/docs/firestore/reference/rest/v1/Write#FieldTransform.FIELDS.increment
increment(Array<string>)

// Set: property name/s to append missing elements
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/Write#FieldTransform.FIELDS.append_missing_elements
append(Array<string>)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@xeaone/database

Import symbol

import * as database from "@xeaone/database";
or

Import directly with a jsr specifier

import * as database from "jsr:@xeaone/database";

Add Package

pnpm i jsr:@xeaone/database
or (using pnpm 10.8 or older)
pnpm dlx jsr add @xeaone/database

Import symbol

import * as database from "@xeaone/database";

Add Package

yarn add jsr:@xeaone/database
or (using Yarn 4.8 or older)
yarn dlx jsr add @xeaone/database

Import symbol

import * as database from "@xeaone/database";

Add Package

npx jsr add @xeaone/database

Import symbol

import * as database from "@xeaone/database";

Add Package

bunx jsr add @xeaone/database

Import symbol

import * as database from "@xeaone/database";