> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Interface: BaseTableWriter<DataModel, TableName>

> Reference for the BaseTableWriter interface in bijection/server.

[server](/api/modules/server).BaseTableWriter

## Type parameters

| Name | Type |
| :- | :- |
| `DataModel` | extends [`GenericDataModel`](/api/modules/server#genericdatamodel) |
| `TableName` | extends [`TableNamesInDataModel`](/api/modules/server#tablenamesindatamodel)\<`DataModel`> |

## Hierarchy

* [`BaseTableReader`](/api/interfaces/server.BaseTableReader)\<`DataModel`, `TableName`>

  ↳ **`BaseTableWriter`**

## Methods

### get

▸ **get**\<`Fields`>(`id`, `options`): `Promise`\<`null` | [`SelectedDocument`](/api/modules/server#selecteddocument)\<[`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>, `Fields`>>

Read selected top-level properties, retaining identity and creation time.

#### Type parameters

| Name | Type |
| :- | :- |
| `Fields` | extends `string` |

#### Parameters

| Name | Type |
| :- | :- |
| `id` | [`TableKey`](/api/modules/server#tablekey)\<`DataModel`, `TableName`> |
| `options` | `Object` |
| `options.select` | readonly `Fields`\[] |

#### Returns

`Promise`\<`null` | [`SelectedDocument`](/api/modules/server#selecteddocument)\<[`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>, `Fields`>>

#### Inherited from

[BaseTableReader](/api/interfaces/server.BaseTableReader).[get](/api/interfaces/server.BaseTableReader#get)

▸ **get**(`id`): `Promise`\<`null` | [`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>>

Fetch a single document from the table by its [GenericId](/api/modules/values#genericid).

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `id` | [`TableKey`](/api/modules/server#tablekey)\<`DataModel`, `TableName`> | The [GenericId](/api/modules/values#genericid) of the document to fetch from the database. |

#### Returns

`Promise`\<`null` | [`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>>

* The [GenericDocument](/api/modules/server#genericdocument) of the document at the given [GenericId](/api/modules/values#genericid), or `null` if it no longer exists.

#### Inherited from

[BaseTableReader](/api/interfaces/server.BaseTableReader).[get](/api/interfaces/server.BaseTableReader#get)

***

### query

▸ **query**(): [`SelectableQueryInitializer`](/api/interfaces/server.SelectableQueryInitializer)\<[`NamedTableInfo`](/api/modules/server#namedtableinfo)\<`DataModel`, `TableName`>>

Begin a query for the table.

Queries don't execute immediately, so calling this method and extending its
query are free until the results are actually used.

#### Returns

[`SelectableQueryInitializer`](/api/interfaces/server.SelectableQueryInitializer)\<[`NamedTableInfo`](/api/modules/server#namedtableinfo)\<`DataModel`, `TableName`>>

* A [QueryInitializer](/api/interfaces/server.QueryInitializer) object to start building a query.

#### Inherited from

[BaseTableReader](/api/interfaces/server.BaseTableReader).[query](/api/interfaces/server.BaseTableReader#query)

***

### insert

▸ **insert**(`value`): `Promise`\<[`GenericId`](/api/modules/values#genericid)\<`TableName`>>

Insert a new document into the table.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `value` | [`WithoutSystemFields`](/api/modules/server#withoutsystemfields)\<[`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>> | The [Value](/api/modules/values#value) to insert into the given table. |

#### Returns

`Promise`\<[`GenericId`](/api/modules/values#genericid)\<`TableName`>>

* [GenericId](/api/modules/values#genericid) of the new document.

***

### patch

▸ **patch**(`id`, `value`): `Promise`\<`void`>

Patch an existing document, shallow merging it with the given partial
document.

New fields are added. Existing fields are overwritten. Fields set to
`undefined` are removed.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `id` | [`GenericId`](/api/modules/values#genericid)\<`TableName`> | The [GenericId](/api/modules/values#genericid) of the document to patch. |
| `value` | `PatchValue`\<[`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>> | The partial [GenericDocument](/api/modules/server#genericdocument) to merge into the specified document. If this new value specifies system fields like `_id`, they must match the document's existing field values. |

#### Returns

`Promise`\<`void`>

***

### replace

▸ **replace**(`id`, `value`): `Promise`\<`void`>

Replace the value of an existing document, overwriting its old value.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `id` | [`GenericId`](/api/modules/values#genericid)\<`TableName`> | The [GenericId](/api/modules/values#genericid) of the document to replace. |
| `value` | [`WithOptionalSystemFields`](/api/modules/server#withoptionalsystemfields)\<[`DocumentByName`](/api/modules/server#documentbyname)\<`DataModel`, `TableName`>> | The new [GenericDocument](/api/modules/server#genericdocument) for the document. This value can omit the system fields, and the database will fill them in. |

#### Returns

`Promise`\<`void`>

***

### delete

▸ **delete**(`id`): `Promise`\<`void`>

Delete an existing document.

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `id` | [`GenericId`](/api/modules/values#genericid)\<`TableName`> | The [GenericId](/api/modules/values#genericid) of the document to remove. |

#### Returns

`Promise`\<`void`>
