Home / Function/ columnMapper() — astro Function Reference

columnMapper() — astro Function Reference

Architecture documentation for the columnMapper() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  3099e947_8164_4013_6b72_f4b301ca60d1["columnMapper()"]
  80ef4dc8_c183_c77f_e09f_d40d9a6ca694["index.ts"]
  3099e947_8164_4013_6b72_f4b301ca60d1 -->|defined in| 80ef4dc8_c183_c77f_e09f_d40d9a6ca694
  29c39cb4_cd06_6b43_331c_079cec6b23f4["asDrizzleTable()"]
  29c39cb4_cd06_6b43_331c_079cec6b23f4 -->|calls| 3099e947_8164_4013_6b72_f4b301ca60d1
  286a245d_f46c_69e1_f4fd_ea9cbafcddb6["handleSerializedSQL()"]
  3099e947_8164_4013_6b72_f4b301ca60d1 -->|calls| 286a245d_f46c_69e1_f4fd_ea9cbafcddb6
  style 3099e947_8164_4013_6b72_f4b301ca60d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/db/src/runtime/index.ts lines 82–131

function columnMapper(columnName: string, column: DBColumn) {
	let c: ReturnType<
		| typeof text
		| typeof integer
		| typeof jsonType
		| typeof dateType
		| typeof integer<string, 'boolean'>
	>;

	switch (column.type) {
		case 'text': {
			c = text(columnName, { enum: column.schema.enum });
			// Duplicate default logic across cases to preserve type inference.
			// No clean generic for every column builder.
			if (column.schema.default !== undefined)
				c = c.default(handleSerializedSQL(column.schema.default));
			if (column.schema.primaryKey === true) c = c.primaryKey();
			break;
		}
		case 'number': {
			c = integer(columnName);
			if (column.schema.default !== undefined)
				c = c.default(handleSerializedSQL(column.schema.default));
			if (column.schema.primaryKey === true) c = c.primaryKey();
			break;
		}
		case 'boolean': {
			c = integer(columnName, { mode: 'boolean' });
			if (column.schema.default !== undefined)
				c = c.default(handleSerializedSQL(column.schema.default));
			break;
		}
		case 'json':
			c = jsonType(columnName);
			if (column.schema.default !== undefined) c = c.default(column.schema.default);
			break;
		case 'date': {
			c = dateType(columnName);
			if (column.schema.default !== undefined) {
				const def = handleSerializedSQL(column.schema.default);
				c = c.default(typeof def === 'string' ? new Date(def) : def);
			}
			break;
		}
	}

	if (!column.schema.optional) c = c.notNull();
	if (column.schema.unique) c = c.unique();
	return c;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does columnMapper() do?
columnMapper() is a function in the astro codebase, defined in packages/db/src/runtime/index.ts.
Where is columnMapper() defined?
columnMapper() is defined in packages/db/src/runtime/index.ts at line 82.
What does columnMapper() call?
columnMapper() calls 1 function(s): handleSerializedSQL.
What calls columnMapper()?
columnMapper() is called by 1 function(s): asDrizzleTable.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free