GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - voznik/ngx-odm: Angular 14+ wrapper for RxDB

BranchesTags
Open more actions menu

Latest commit

 

History

87 Commits
87 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude
.claude
 
 
.gemini
.gemini
 
 
.github
.github
 
 
.husky
.husky
 
 
.vscode
.vscode
 
 
.zed
.zed
 
 
examples
examples
 
 
packages
packages
 
 
tools
tools
 
 
.actrc
.actrc
 
 
.aiignore
.aiignore
 
 
.commitlintrc.json
.commitlintrc.json
 
 
.compodocrc.json
.compodocrc.json
 
 
.editorconfig
.editorconfig
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
.lintstagedrc.json
.lintstagedrc.json
 
 
.npmignore
.npmignore
 
 
.npmrc
.npmrc
 
 
.nvmrc
.nvmrc
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
.renovaterc.json
.renovaterc.json
 
 
.secrets.template
.secrets.template
 
 
AGENTS.md
AGENTS.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE.txt
LICENSE.txt
 
 
NOTES.md
NOTES.md
 
 
README.md
README.md
 
 
RELEASE.md
RELEASE.md
 
 
docker-compose.couch.yml
docker-compose.couch.yml
 
 
docker-compose.kinto.yml
docker-compose.kinto.yml
 
 
eslint.config.mjs
eslint.config.mjs
 
 
image.png
image.png
 
 
jest.config.ts
jest.config.ts
 
 
jest.preset.js
jest.preset.js
 
 
kinto.env
kinto.env
 
 
migrations.json
migrations.json
 
 
nx.json
nx.json
 
 
opencode.json
opencode.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.base.json
tsconfig.base.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

@ngx-odm/rxdb

Angular 14+ wrapper for RxDB - A realtime Database for the Web

Demo

Example Screencast

demo - based on TodoMVC

Table of contents

  • @ngx-odm/rxdb
    • Demo
    • Table of contents
    • General info
    • Technologies
    • Install
    • Usage (NgModule)
      • In your AppModule
      • In your FeatureModule
      • In your FeatureService
    • Usage (Standalone)
      • In your main.ts
      • In your Component
      • Using sginals & signalStore from @ngrx/signals
    • Features
    • Status
    • Inspiration
    • Notes
    • Contact

General info

If you don't want to setup RxDB manually in your next Angular project - just import NgxRxdbModule or go with provideRxDatabase and provideRxCollection if standalone component is your choice.

Technologies

RxDB 16+ Angular 17+
RxDB Angular

Install

npm install @ngx-odm/rxdb

Usage (NgModule)

In your AppModule

import { NgxRxdbModule } from '@ngx-odm/rxdb';
import { getRxDatabaseCreator } from '@ngx-odm/rxdb/config';

@NgModule({
  imports: [
    // ... other imports
    NgxRxdbModule.forRoot(
      getRxDatabaseCreator({
        name: 'demo', // <- name (required, 'ngx')
        storage: getRxStorageDexie(), // <- storage (not required, 'dexie')
        localDocuments: true,
        multiInstance: true, // <- multiInstance (optional, default: true)
        ignoreDuplicate: false,
        options: {
          plugins: [
            // will be loaded by together with core plugins
            RxDBDevModePlugin, // <- add only for development
            RxDBAttachmentsPlugin,
            RxDBLeaderElectionPlugin,
          ],
          storageType: 'dexie|memory', // <- storageType (optional, use if you want defaults provided automatically)
          dumpPath: 'assets/dump.json', // path to datbase dump file (optional)
        },
      })
    ),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

In your FeatureModule

Schemas define how your data looks. Which field should be used as primary, which fields should be used as indexes and what should be encrypted. The schema also validates that every inserted document of your collections conforms to the schema. Every collection has its own schema. With RxDB, schemas are defined with the jsonschema-standard which you might know from other projects. https://rxdb.info/rx-schema.html

import type { RxCollectionCreatorExtended } from '@ngx-odm/rxdb/config';
// create or import your schema
const todoSchema: RxSchema = require('../../../assets/data/todo.schema.json');
// create config
const todoCollectionConfig: RxCollectionCreatorExtended = {
  name: 'todo', // <- name (required)
  schema: todoSchema, // <- schema (not required, see below)
  localDocuments: true,
  options: {
    initialDocs: [], // docs to be imported into empty collection (optional)
    schemaUrl: 'assets/data/todo.schema.json', // load schema from remote url (optional)
    replicationStateFactory: collection => {
      // provide replication state (optional)
    },
  },
};

@NgModule({
  imports: [
    // ... other imports
    NgxRxdbModule.forFeature(todoCollectionConfig),
  ],
})
export class TodosModule {
  constructor(
    @Inject(RXDB_COLLECTION) private collectionService: RxDBCollectionService<Todo>
  ) {
    this.collectionService.sync(); // INFO: collection is ready
  }
}

In your FeatureService

import { RXDB_COLLECTION } from '@ngx-odm/rxdb';
import { RxDBCollectionService } from '@ngx-odm/rxdb/collection';

@Injectable()
export class TodosService {
  private collectionService: RxDBCollectionService<Todo> =
    inject<RxDBCollectionService<Todo>>(RXDB_COLLECTION);
  // store & get filter as property of a `local` document
  filter$ = this.collectionService
    .getLocal('local', 'filterValue')
    .pipe(startWith('ALL'), distinctUntilChanged());
  // get count of documents in collection as observable
  count$ = this.collectionService.count();

  // get documents from collection as observable
  // optionally using `RxQuery` mango-queries
  todos$: Observable<Todo[]> = this.collectionService.docs();

  // add new document
  add(name: string): void {
    const payload: Todo = { guid: uuid(), name, done: false, dateCreated: Date.now() };
    this.collectionService.insert(payload);
  }

  // update property of single document
  toggle(guid: string, done: boolean): void {
    this.collectionService.set(guid, { done });
  }

  // update many documents with partial data by query
  toggleAllTodos(completed: boolean) {
    this.collectionService.updateBulk(
      { selector: { completed: { $eq: !completed } } },
      { completed }
    );
  }

  // remove many dcouments by qeury
  removeCompletedTodos(): void {
    this.collectionService.removeBulk({ selector: { completed: true } });
  }
  // ...
}

Usage (Standalone)

In your main.ts

import { provideRxDatabase } from '@ngx-odm/rxdb';
import { getRxDatabaseCreator } from '@ngx-odm/rxdb/config';

export const appConfig: ApplicationConfig = {
  providers: [
    // ... other providers
    provideRxDatabase(
      getRxDatabaseCreator({
        name: 'demo',
        localDocuments: true,
        multiInstance: true,
        ignoreDuplicate: false,
        storage: getRxStorageDexie(),
        plugins: [
          // will be loaded by together with core plugins
          RxDBDevModePlugin, // <- add only for development
          RxDBAttachmentsPlugin,
          RxDBLeaderElectionPlugin,
        ],
      })
    ),
  ],
};

bootstrapApplication(AppComponent, appConfig).catch(err => console.error(err));

In your Component

import { provideRxCollection } from '@ngx-odm/rxdb';

@Component({
  standalone: true,
  // ...
  providers: [provideRxCollection(config)],
})
export class StandaloneComponent {
  readonly todoCollection = inject(NgxRxdbCollectionService<Todo>);
}

Using sginals & signalStore from @ngrx/signals

import { signalStore } from '@ngrx/signals';
import { withEntities } from '@ngrx/signals/entities';
import { withCollectionService } from '@ngx-odm/rxdb/signals';
import { withDevtools } from '@angular-architects/ngrx-toolkit';

export const TodoStore = signalStore(
  { providedIn: 'root' },
  withDevtools('todo'),
  withEntities<Todo>(),
  // INFO: an instance of RxCollection will be provided by this
  withCollectionService<Todo, TodosFilter, RxCollectionCreatorExtended>({
    filter: 'ALL' as TodosFilter,
    collectionConfig: TodosCollectionConfig,
  }),
  ...
);

@Component({
  standalone: true,
  // ...
  providers: [TodoStore],
})
export class StandaloneComponent {
  readonly todoStore = inject(TodoStore);

  constructor() {
    effect(() => {
      const { filter, entities } = this.todoStore;
    });
  }
}

Features

By using this module you can simplify your work with RxDB in Angular application:

  • Automatically initialize db with settings
    • optionally provide db dumb to pre-fill collections
    • optionally provide array of initial documents to pre-fill collection
    • optionally provide remote location for schema and fetch it automatically before create collection (e.g. to maintain single source of truth for schema)
    • optionally provide syncronization with remote db (CouchDB, Kinto etc.) as DB options
  • Automatically initialize RxCollection for each lazy-loaded Feature module / standalone component with config
  • Work with documents via NgxRxdbCollectionService with unified methods instead of using RxCollection directly (though you still have access to RxCollection and RxDatabase instance)
    • simple methods to work database & documents (with queries)
    • simple methods to work with local documents
    • simple methods to work with attachments
    • simple replication sync initialization
  • Work with signals and entities with @ngrx/signals and @ngrx/entity (supports native zoneless via provideZonelessChangeDetection()) (see example)
  • Persist collection query (mango-query-syntax) in URL with new plugin query-params-plugin (in demo, set localStorage _ngx_rxdb_queryparams )
    • provide Observable of current URL (automatically for Angular)
    • simple methods to set or patch filter, sort, limit, skip

Status

Project is: in progress

Inspiration

Project inspired by

  • rxdb-angular2-example
  • Angular NgRx Material Starter
  • The Angular Library Series from Angular In Depth
  • NgRx Toolkit - inspired by Manfred Steyer and created singnals tool by analogy of withDataService from Angular Architects

Notes

Contact

Created by @voznik - feel free to contact me!

About

Angular 14+ wrapper for RxDB

voznik.github.io/ngx-odm

Topics

angularkintolibrarynosqlpouchdbreplicationrxdbrxjsstreamlit-componenttypescript

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

48 stars

Watchers

0 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.