MCPcopy Index your code
hub / github.com/outerbase/studio / parseColumnConstraint

Function parseColumnConstraint

src/drivers/sqlite/sql-parse-table.ts:211–416  ·  view source on GitHub ↗
(
  schemaName: string,
  cursor: CursorV2
)

Source from the content-addressed store, hash-verified

209}
210
211export function parseColumnConstraint(
212 schemaName: string,
213 cursor: CursorV2
214): DatabaseTableColumnConstraint | undefined {
215 if (cursor.match("CONSTRAINT")) {
216 cursor.next();
217 const constraintName = cursor.consume();
218
219 return {
220 ...parseColumnConstraint(schemaName, cursor),
221 name: constraintName,
222 };
223 } else if (cursor.match("PRIMARY")) {
224 let primaryKeyOrder: SqlOrder | undefined;
225 let primaryColumns: string[] | undefined;
226 let autoIncrement = false;
227
228 cursor.next();
229 if (!cursor.match("KEY")) throw new Error("PRIMARY must follow by KEY");
230
231 cursor.next();
232
233 if (cursor.match("(")) {
234 primaryColumns = parseColumnList(cursor.consumeParen());
235 }
236
237 if (cursor.match("ASC")) {
238 primaryKeyOrder = "ASC";
239 cursor.next();
240 } else if (cursor.match("DESC")) {
241 primaryKeyOrder = "DESC";
242 cursor.next();
243 }
244
245 const conflict = parseConstraintConflict(cursor);
246
247 if (cursor.match("AUTOINCREMENT")) {
248 autoIncrement = true;
249 cursor.next();
250 }
251
252 return {
253 primaryKey: true,
254 primaryKeyOrder,
255 primaryColumns,
256 autoIncrement,
257 primaryKeyConflict: conflict,
258 ...parseColumnConstraint(schemaName, cursor),
259 };
260 } else if (cursor.match("NOT")) {
261 cursor.next();
262 if (!cursor.match("NULL")) throw new Error("NOT should follow by NULL");
263 cursor.next();
264
265 const conflict = parseConstraintConflict(cursor);
266 return {
267 notNull: true,
268 notNullConflict: conflict,

Callers 3

pccFunction · 0.90
parseColumnDefFunction · 0.85
parseTableDefinitionFunction · 0.85

Calls 12

parseColumnListFunction · 0.85
parseConstraintConflictFunction · 0.85
nextMethod · 0.80
consumeMethod · 0.80
consumeParenMethod · 0.80
readMethod · 0.80
currentTypeMethod · 0.80
consumeIdentifierMethod · 0.80
endMethod · 0.80
consumeBlockMethod · 0.80
matchMethod · 0.45
toStringMethod · 0.45

Tested by 1

pccFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…