Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Interfaces

Functions

Functions

set

  • set<Model>(ref: Ref<Model>, data: Model, options?: SetOptions): Promise<Doc<Model>>
  • set<Model>(collection: Collection<Model>, id: string, data: Model, options?: SetOptions): Promise<Doc<Model>>
  • Sets a document to the given data.

    import { set, collection } from 'typesaurus'
    
    type User = { name: string }
    const users = collection<User>('users')
    
    set(users, '00sHm46UWKObv2W7XK9e', { name: 'Sasha Koss' }).then(sasha => {
      console.log(sasha.data)
      //=> { name: 'Sasha Koss' }
    })

    You can also preseve current fields not specified by set:

    import { set, value, get, collection } from 'typesaurus'
    
    type User = { name: string, registedAt: Date }
    const users = collection<User>('users')
    
    set(users, '00sHm46UWKObv2W7XK9e', {
      name: 'Sasha',
      registedAt: value('serverDate')
    },
    
    set(
      users,
     '00sHm46UWKObv2W7XK9e',
      { name: 'Sasha Koss' },
      { merge: true }
    )
      .then(({ ref }) => get(ref))
      .then(console.log)
      //=> { name: 'Sasha Koss', registedAt: Thu Aug 15 2019 16:16:56 GMT+0200 (Central European Summer Time) }

    Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      the reference to the document to set

    • data: Model
    • Optional options: SetOptions

      { merge: boolean (default: false) }

    Returns Promise<Doc<Model>>

    A promise to the document

  • Sets a document to the given data.

    import { set, collection } from 'typesaurus'
    
    type User = { name: string }
    const users = collection<User>('users')
    
    set(users, '00sHm46UWKObv2W7XK9e', { name: 'Sasha Koss' }).then(sasha => {
      console.log(sasha.data)
      //=> { name: 'Sasha Koss' }
    })

    You can also preseve current fields not specified by set:

    import { set, value, get, collection } from 'typesaurus'
    
    type User = { name: string, registedAt: Date }
    const users = collection<User>('users')
    
    set(users, '00sHm46UWKObv2W7XK9e', {
      name: 'Sasha',
      registedAt: value('serverDate')
    },
    
    set(
      users,
     '00sHm46UWKObv2W7XK9e',
      { name: 'Sasha Koss' },
      { merge: true }
    )
      .then(({ ref }) => get(ref))
      .then(console.log)
      //=> { name: 'Sasha Koss', registedAt: Thu Aug 15 2019 16:16:56 GMT+0200 (Central European Summer Time) }

    Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      the collection to set document in

    • id: string

      the id of the document to set

    • data: Model

      the document data

    • Optional options: SetOptions

      { merge: boolean (default: false) }

    Returns Promise<Doc<Model>>

    A promise to the document

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc