Interface TableInsertOneResult<PKey>

Overview

Represents the result of an insertOne command on a table.

Primary Key Inference

The type of the primary key of the table is inferred from the second PKey type-param of the table.

If not present, it defaults to Partial<RSchema> to keep the result type consistent.

Example

interface User {
  id: string,
  name: string,
  dob?: DataAPIDate,
}

type UserPKey = Pick<User, 'id'>;

const table = db.table<User, UserPKey>('table');

// res.insertedId is of type { id: string }
const res = await table.insertOne({ id: '123', name: 'Alice' });
console.log(res.insertedId.id); // '123'

Example

const table = db.table<User>('table');

// res.insertedId is of type Partial<User>
const res = await table.insertOne({ id: '123', name: 'Alice' });
console.log(res.insertedId.id); // '123'
console.log(res.insertedId.key); // undefined

Field

insertedId - The primary key of the inserted document.

See

Table.insertOne

interface TableInsertOneResult<PKey> {
    insertedId: PKey;
}

Type Parameters

Properties

Properties

insertedId: PKey

The primary key of the inserted document.

See TableInsertOneResult for more info about this type and how it's inferred.