Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xeaone/database
X-Database A Deno database client for Google Cloud Firestore.
https://github.com/xeaone/database
database datastore deno firebase firestore gcp google javascript typescript
Last synced: 3 months ago
JSON representation
X-Database A Deno database client for Google Cloud Firestore.
- Host: GitHub
- URL: https://github.com/xeaone/database
- Owner: xeaone
- License: mit
- Created: 2022-03-29T21:28:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-13T20:16:00.000Z (10 months ago)
- Last Synced: 2024-04-14T12:13:35.948Z (9 months ago)
- Topics: database, datastore, deno, firebase, firestore, gcp, google, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 148 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![deno module](https://shield.deno.dev/x/xdatabase)](https://deno.land/x/xdatabase) ![deno compatibility](https://shield.deno.dev/deno/^1.33.3) ![GitHub](https://img.shields.io/github/license/xeaone/database)
# X-Database
A Deno database client for Google Cloud Firestore.
## Example
```ts
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)`
```ts
const users = await database.search('user').equal({ id: '1' }).end();
```### `view(collection: string)`
```ts
const user = await database.view('user').equal({ id: '1' }).end();
```### `remove(collection: string)`
```ts
const user = await database.remove('user').identifier('1').end();
```### `create(collection: string, data: Data)`
```ts
const user = await database.create('user', {
id: '1',
name: 'foo bar',
age: 42,
}).identifier('1').end();
```### `update(collection: string, data: Data)`
```ts
const user = await database.update('user', { age: 69 }).equal({ id: '1' })
.end();
```### `commit(collection: string, data: Data)`
```ts
const user = await database.commit('user').equal({ id: '1' }).increment({
age: 1,
}).end();
```### `Options`
```ts
// All Except Search:
identifier(string)// All Except Set: Property starts with filter
startsWith(Array)// All Except Set:
in(Array)// All Except Set:
notIn(Array)// All Except Set: default
equal(Array)// All Except Set:
notEqual(Array)// All Except Set:
lessThan(Array)// All Except Set:
lessThanOrEqual(Array)// All Except Set:
arrayContains(Array)// All Except Set:
arrayContainsAny(Array)// All Except Set:
greaterThan(Array;// All Except Set:
greaterThanOrEqual(Array)// Search: orders results by property name/s
ascending(Array)
descending(Array)// Search:
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.start_at
start(Array>)// Search:
// Firestore: https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#FIELDS.end_at
end(Array>)// 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)// 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)
```