update()

Description

Update an object in the database

To delete a file, just set the value to an empty string during the update request

You do not need to pass the entire object to update it. The system will only update the values that have been passed.

Request

Parameters

FieldRequiredData TypeDescription

uid

string

UID of the object to update

body

Object

Object to update in the database. Note: it must follow the database schema. Otherwise, 422 error will be returned.

options

Object

Object containing additional request parameters

Options Object Parameters

FieldRequiredData TypeDescription

skipFileExceptions

boolean

If set to true will skip file upload exceptions in the back-end and will return 200 even if there is an error during downloading/uploading of files.

Examples

Update

const product = await client.database().from('products').update("tTvKpi6E7N68Xv8RJOug", {
    "name": "Hat",
    "price": 12,
    "image": "https://images.unsplash.com/photo-1588850561407-ed78c282e89b?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1036&q=80"
})

Update and skip file upload errors

const product = await client.database().from('products').update("tTvKpi6E7N68Xv8RJOug", 
    {
        "name": "Hat",
        "price": 12,
        "image": "https://images.unsplash.com/photo-1588850561407-ed78c282e89b?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1036&q=80"
    },
    {
        "skipFileExceptions": true
    }
)

Response

Parameters

FieldData TypeDescription

data

Object

Object containing all database item values

meta

Object

info

Object

Object containing operation information

Metadata Parameters

FieldData TypeDescription

total

number

Total number of items in with the given UID Always equal to 1

page

number

Current page number Always equal to 1

limit

number

Current limit per page Always equal to 1

includesCount

number

Number of additional requests for the includes operations

Always equal to 0

Info Parameters

FieldData TypeDescription

action

string

Operation name

webhooksTriggered

number

Number of webhooks triggered by the operation

Example

This is an example response to the Update and skip file upload errors request example above with an imaginary error during file upload. As you can see, the object is still created, but the image property is set to an empty string.

{
    "data": {
        "uid": "tTvKpi6E7N68Xv8RJOug"
        "name": "Hat",
        "price": 12,
        "image": "",
        "createdAt": "2022-08-22T16:04:49-04:00",
        "updatedAt": "2022-08-22T16:04:51-04:00"
    },
    "meta": {
        "total": 1,
        "page": 1,
        "limit": 1,
        "includesCount": 0
    },
    "info": {
        "action": "patch",
        "webhooksTriggered": 0
    }
}

Last updated

Copyright © 2023 Deskree Technologies Inc.