MCPcopy
hub / github.com/remix-run/remix / table

Function table

packages/data-table/src/lib/table.ts:718–773  ·  view source on GitHub ↗
(
  options: CreateTableOptions<name, columns, primaryKey>,
)

Source from the content-addressed store, hash-verified

716 * ```
717 */
718export function table<
719 name extends string,
720 columns extends TableColumnsDefinition,
721 primaryKey extends
722 | ColumnNameFromColumns<columns>
723 | readonly ColumnNameFromColumns<columns>[]
724 | undefined = undefined,
725>(
726 options: CreateTableOptions<name, columns, primaryKey>,
727): Table<name, columns, NormalizePrimaryKey<columns, primaryKey>> {
728 let tableName = options.name
729 let columns = options.columns
730
731 let resolvedPrimaryKey = normalizePrimaryKey(tableName, columns, options.primaryKey)
732 let timestampConfig = normalizeTimestampConfig(options.timestamps)
733 let columnDefinitions = resolveTableColumns(tableName, columns)
734 let table = Object.create(null) as Table<name, columns, NormalizePrimaryKey<columns, primaryKey>>
735
736 Object.defineProperty(table, tableMetadataKey, {
737 value: Object.freeze({
738 name: tableName,
739 columns,
740 primaryKey: resolvedPrimaryKey,
741 timestamps: timestampConfig,
742 columnDefinitions,
743 beforeWrite: options.beforeWrite as
744 | TableBeforeWrite<TableRowFromColumns<columns>>
745 | undefined,
746 afterWrite: options.afterWrite as TableAfterWrite<TableRowFromColumns<columns>> | undefined,
747 beforeDelete: options.beforeDelete as TableBeforeDelete | undefined,
748 afterDelete: options.afterDelete as TableAfterDelete | undefined,
749 afterRead: options.afterRead as TableAfterRead<TableRowFromColumns<columns>> | undefined,
750 validate: options.validate as TableValidate<TableRowFromColumns<columns>> | undefined,
751 }),
752 enumerable: false,
753 writable: false,
754 configurable: false,
755 })
756
757 for (let columnName in columns) {
758 if (!Object.prototype.hasOwnProperty.call(columns, columnName)) {
759 continue
760 }
761
762 let column = createColumnReference(tableName, columnName)
763
764 Object.defineProperty(table, columnName, {
765 value: column,
766 enumerable: true,
767 writable: false,
768 configurable: false,
769 })
770 }
771
772 return Object.freeze(table) as Table<name, columns, NormalizePrimaryKey<columns, primaryKey>>
773}
774
775function createColumnReference<tableName extends string, columnName extends string>(

Callers 15

adapter.test.tsFile · 0.90
operators.test.tsFile · 0.90
table.test.tsFile · 0.90
database.test.tsFile · 0.90
references.test.tsFile · 0.90
adapter.test.tsFile · 0.90

Calls 5

normalizePrimaryKeyFunction · 0.85
normalizeTimestampConfigFunction · 0.85
resolveTableColumnsFunction · 0.85
createColumnReferenceFunction · 0.85
createMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…