{"id":20328033,"url":"https://github.com/vandaeldev/ngx-surreal","last_synced_at":"2025-05-08T01:30:48.162Z","repository":{"id":245442792,"uuid":"815595426","full_name":"vandaeldev/ngx-surreal","owner":"vandaeldev","description":"Lightweight Angular wrapper for the SurrealDB JavaScript SDK","archived":false,"fork":false,"pushed_at":"2024-09-18T15:12:07.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-02T08:10:02.624Z","etag":null,"topics":["angular-surreal","surrealdb-client"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vandaeldev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-15T15:18:54.000Z","updated_at":"2024-10-15T03:31:41.000Z","dependencies_parsed_at":"2024-06-22T05:44:37.844Z","dependency_job_id":"29a42350-687a-4a30-8d8e-f0bad912e911","html_url":"https://github.com/vandaeldev/ngx-surreal","commit_stats":null,"previous_names":["vandaeldev/ngx-surreal"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vandaeldev%2Fngx-surreal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vandaeldev%2Fngx-surreal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vandaeldev%2Fngx-surreal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vandaeldev%2Fngx-surreal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vandaeldev","download_url":"https://codeload.github.com/vandaeldev/ngx-surreal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252981422,"owners_count":21835424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular-surreal","surrealdb-client"],"created_at":"2024-11-14T20:00:49.477Z","updated_at":"2025-05-08T01:30:48.118Z","avatar_url":"https://github.com/vandaeldev.png","language":"TypeScript","funding_links":[],"categories":["Framework Interoperability"],"sub_categories":["Wrappers"],"readme":"# ngx-surreal\n\n- [Introduction](#introduction)\n- [Compatibility](#compatibility)\n- [Installation](#installation)\n- [Initialization](#initialization)\n  - [With standalone bootstrap](#with-standalone-bootstrap)\n  - [With NgModule bootstrap](#with-ngmodule-bootstrap)\n- [Configuration](#configuration)\n- [Usage](#usage)\n- [Links](#links)\n\n## Introduction\n\nThis package is a simple wrapper around the [SurrealDB JavaScript SDK](https://www.npmjs.com/package/surrealdb.js). It exposes almost all of the same methods as the SDK, only converted to [RxJS `Observable`s](https://rxjs.dev/guide/observable) to make it easier to use within a standard Angular application. It also re-exports some classes and types from the SDK.\nOn service initialization, it sets up a single connection with the configuration supplied in the `SurrealModule.forRoot()` method.\n\n## Compatibility\n\n|ngx-surreal|Angular |SurrealDB   |\n|-----------|--------|------------|\n|^0.2.1     |\u003e=18.0.0|^1.0.0      |\n|^1.0.0     |\u003e=18.0.0|^2.0.0      |\n\n## Installation\n\n```sh\n# npm\nnpm install ngx-surreal\n\n# pnpm\npnpm add ngx-surreal\n\n# yarn\nyarn add ngx-surrreal\n\n# bun\nbun add ngx-surreal\n```\n\n## Initialization\n\nThis package exposes a module called `SurrealModule` with only one method: `forRoot()`. The `forRoot()` method takes an object of type `SurrealConfig` with SurrealDB connection options.\n\n### With standalone bootstrap\n\n```ts\nimport { importProvidersFrom, type ApplicationConfig } from '@angular/core';\nimport { provideRouter } from '@angular/router';\nimport { SurrealModule, type SurrealConfig } from 'ngx-surreal';\nimport { routes } from './app.routes';\n\nconst surrealConfig: SurrealConfig = {\n  url: 'http://localhost:8000/rpc',\n  namespace: 'test',\n  database: 'test'\n};\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideRouter(routes),\n    importProvidersFrom(SurrealModule.forRoot(surrealConfig))\n  ]\n};\n```\n\n### With NgModule bootstrap\n\n```ts\nimport { NgModule } from '@angular/core';\nimport { BrowserModule } from '@angular/platform-browser';\nimport { SurrealModule, type SurrealConfig } from 'ngx-surreal';\nimport { AppComponent } from './app.component';\n\nconst surrealConfig: SurrealConfig = {\n  url: 'http://localhost:8000/rpc',\n  namespace: 'test',\n  database: 'test'\n};\n\n@NgModule({\n  declarations: [AppComponent],\n  imports: [\n    BrowserModule,\n    SurrealModule.forRoot(surrealConfig)\n  ],\n  bootstrap: [AppComponent]\n})\nexport class AppModule {}\n```\n\n## Configuration\n\nThe type definition for `SurrealConfig` is as follows:\n\n```ts\nimport type { Surreal } from 'surrealdb';\n\nexport type ConnectionOptions = Parameters\u003cSurreal['connect']\u003e[1];\nexport type SurrealConfig = ConnectionOptions \u0026 { url: string };\n```\n\nThe following options are available for configuration:\n\n```ts\nurl: string;\nnamespace?: string;\ndatabase?: string;\nauth?: AnyAuth | Token;\nprepare?: (connection: Surreal) =\u003e unknown;\nversionCheck?: boolean;\nversionCheckTimeout?: number;\n```\n\n## Usage\n\n```ts\nimport { Component, signal, type OnInit } from '@angular/core';\nimport { SurrealService, RecordId, PreparedQuery } from 'ngx-surreal';\n\n@Component({\n  selector: 'app-example',\n  templateUrl: 'example.component.html',\n  styleUrl: 'example.component.scss'\n})\nexport class ExampleComponent implements OnInit {\n  public readonly items = signal([]);\n  public readonly singleItem = signal({});\n\n  private readonly surrealService = inject(SurrealService);\n  // or\n  constructor(private readonly surrealService: SurrealService) {}\n\n  public ngOnInit() {\n    console.log(this.surrealService.status());\n  }\n\n  public signup(email: string, password: string) {\n    this.surrealService.signup({scope: 'user', email, password}).subscribe(console.log);\n  }\n\n  public signin(email: string, password: string) {\n    this.surrealService.signin({scope: 'user', email, password}).subscribe(console.log);\n  }\n\n  public fetchAllItems() {\n    this.surrealService.select('example').subscribe(records =\u003e this.items.set(records));\n  }\n\n  public fetchItem(id: string) {\n    const recordId = new RecordId('example', id);\n    this.surrealService.select(recordId).subscribe(record =\u003e this.singleItem.set(record));\n  }\n\n  public updateItem(id: string, updates: Record\u003cstring, unknown\u003e) {\n    this.surrealService.update(`example:${id}`, updates).subscribe(console.dir);\n  }\n\n  public deleteItem(id: string) {\n    const recordId = new RecordId('example', id);\n    this.surrealService.delete(recordId).subscribe(console.dir);\n  }\n\n  public queryAllItems() {\n    this.surrealService.query('select * from example; select * from type::table($table)', {table: 'example2'}).subscribe(console.dir);\n    // or\n    const query = new PreparedQuery('select * from type::table($table)', {table: 'example'});\n    this.surrealService.query(query).subscribe(console.dir);\n  }\n}\n```\n\nSee for more examples and all available methods the [SurrealDB JavaScript SDK](https://surrealdb.com/docs/sdk/javascript/methods).\n\n## Links\n\n- [Angular docs](https://angular.dev/overview)\n- [SurrealDB docs](https://surrealdb.com/docs/surrealdb/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvandaeldev%2Fngx-surreal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvandaeldev%2Fngx-surreal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvandaeldev%2Fngx-surreal/lists"}