MCPcopy Create free account
hub / github.com/andywer/postguard / assertCompleteInsertValues

Function assertCompleteInsertValues

src/validation.ts:76–101  ·  view source on GitHub ↗
(query: Query, tables: TableSchema[])

Source from the content-addressed store, hash-verified

74}
75
76function assertCompleteInsertValues(query: Query, tables: TableSchema[]) {
77 // FIXME: Consider SELECT INTO queries as well
78 if (query.type !== "INSERT") return
79 if (query.referencedColumns.some(isUnresolvableColumnReference)) return
80
81 const schema = assertIntactTableRef(query.referencedTables[0], tables)
82
83 const mandatoryColumns = schema.columnNames
84 .map(columnName => ({ ...schema.columnDescriptors[columnName], columnName }))
85 .filter(descriptor => !descriptor.hasDefault)
86
87 const queryColumns = [...query.referencedColumns, ...resolveColumnReferences(query, tables)]
88
89 for (const mandatoryColumn of mandatoryColumns) {
90 const columnReference = queryColumns.find(
91 columnRef => columnRef.columnName === mandatoryColumn.columnName
92 )
93
94 if (!columnReference) {
95 const error = new Error(
96 `Column "${mandatoryColumn.columnName}" is missing from INSERT statement.`
97 )
98 throw augmentValidationError(error, query.path, query)
99 }
100 }
101}
102
103function resolveColumnRefsToTableSchemaDescriptor(
104 returnedColumns: ColumnReference[],

Callers 1

validateSubqueryFunction · 0.85

Calls 3

resolveColumnReferencesFunction · 0.90
augmentValidationErrorFunction · 0.90
assertIntactTableRefFunction · 0.85

Tested by

no test coverage detected