Represents the result of an insertOne command on a table.
insertOne
The type of the primary key of the table is inferred from the second PKey type-param of the table.
PKey
If not present, it defaults to Partial<RSchema> to keep the result type consistent.
Partial<RSchema>
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' Copy
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'
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 Copy
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
insertedId - The primary key of the inserted document.
Table.insertOne
The primary key of the inserted document.
See TableInsertOneResult for more info about this type and how it's inferred.
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
Example
Field
insertedId - The primary key of the inserted document.
See
Table.insertOne