Interface DbSerDesConfigBeta

Overview

The config for common table/collection serialization/deserialization logic.

Such custom logic may be used for various purposes, such as:

  • Integrating your own custom data types
  • Validating data before it's sent to the database, or after it's received
  • Adding support for datatypes not yet supported by the client
Disclaimer

This is an advanced feature, and should be used with caution. It's possible to break the client's behavior by using this feature incorrectly.

These features are currently generally unstable, and should generally not be used in production (except for a couple, such as mutateInPlace or enableBigNumbers).

See the official DataStax documentation for more info.

See

  • CollectionSerDesConfig
  • TableSerDesConfig
  • $SerializeForCollections
  • $SerializeForTables
interface DbSerDesConfig {
    collection?: Omit<CollectionSerDesConfig, "mutateInPlace">;
    mutateInPlace?: boolean;
    table?: Omit<TableSerDesConfig, "mutateInPlace">;
}

Properties

collection?: Omit<CollectionSerDesConfig, "mutateInPlace">

Advanced & currently somewhat unstable features related to customizing spawned collections' ser/des behavior at a lower level.

Use with caution. See official DataStax documentation for more info.

mutateInPlace?: boolean
Overview

Enables an optimization which allows inserted rows/documents to be mutated in-place when serializing.

Context

For example, when you insert a record like so:

import { uuid } from '@datastax/astra-db-ts';
await collection.insertOne({ name: 'Alice', friends: { john: uuid('...') } });

The document is internally serialized as such:

{ name: 'Alice', friends: { john: { $uuid: '...' } } }

To avoid mutating a user-provided object, the client will be forced to clone any objects that contain a custom datatype, as well as their parents (which looks something like this):

{ ...original, friends: { ...original.friends, john: { $uuid: '...' } } }
Enabling this option

This can be a minor performance hit, especially for large objects, so if you're confident that you won't be needing the object after it's inserted, you can enable this option to avoid the cloning, and instead mutate the object in-place.

Example

// Before
const collection = db.collection<User>('users');

const doc = { name: 'Alice', friends: { john: uuid(4) } };
await collection.insertOne(doc);

console.log(doc); // { name: 'Alice', friends: { john: UUID<4>('...') } }

// After
const collection = db.collection<User>('users', {
  serdes: { mutateInPlace: true },
});

const doc = { name: 'Alice', friends: { john: UUID.v4() } };
await collection.insertOne(doc);

console.log(doc); // { name: 'Alice', friends: { john: { $uuid: '...' } } }

Default Value

false
table?: Omit<TableSerDesConfig, "mutateInPlace">

Advanced & currently somewhat unstable features related to customizing spawned tables' ser/des behavior at a lower level.

Use with caution. See official DataStax documentation for more info.