@@ -151,7 +151,7 @@ export const MAX_SQL_QUERY_SIZE = 100000
151
151
export const SLICE_SIZE = 70000
152
152
153
153
// Convert collection data to SQL insert statement
154
- export function generateCollectionInsert ( collection : ResolvedCollection , data : ParsedContentFile ) : { queries : string [ ] , hash : string } {
154
+ export function generateCollectionInsert ( collection : ResolvedCollection , data : ParsedContentFile , opts : { hashColumn ?: boolean } = { } ) : { queries : string [ ] , hash : string } {
155
155
const fields : string [ ] = [ ]
156
156
const values : Array < string | number | boolean > = [ ]
157
157
const sortedKeys = getOrderedSchemaKeys ( ( collection . extendedSchema ) . shape )
@@ -191,8 +191,9 @@ export function generateCollectionInsert(collection: ResolvedCollection, data: P
191
191
} )
192
192
193
193
const valuesHash = hash ( values )
194
-
195
- values . push ( `'${ valuesHash } '` )
194
+ if ( opts . hashColumn !== false ) {
195
+ values . push ( `'${ valuesHash } '` )
196
+ }
196
197
197
198
let index = 0
198
199
const sql = `INSERT INTO ${ collection . tableName } VALUES (${ '?, ' . repeat ( values . length ) . slice ( 0 , - 2 ) } );`
@@ -236,7 +237,7 @@ export function generateCollectionInsert(collection: ResolvedCollection, data: P
236
237
}
237
238
238
239
// Convert a collection with Zod schema to SQL table definition
239
- export function generateCollectionTableDefinition ( collection : ResolvedCollection , opts : { drop ?: boolean } = { } ) {
240
+ export function generateCollectionTableDefinition ( collection : ResolvedCollection , opts : { drop ?: boolean , hashColumn ?: boolean } = { } ) {
240
241
const sortedKeys = getOrderedSchemaKeys ( ( collection . extendedSchema ) . shape )
241
242
const sqlFields = sortedKeys . map ( ( key ) => {
242
243
const type = ( collection . extendedSchema ) . shape [ key ] !
@@ -281,8 +282,10 @@ export function generateCollectionTableDefinition(collection: ResolvedCollection
281
282
return `"${ key } " ${ sqlType } ${ constraints . join ( ' ' ) } `
282
283
} )
283
284
284
- // add __hash__ field for inserts
285
- sqlFields . push ( '"__hash__" TEXT UNIQUE' )
285
+ if ( opts . hashColumn !== false ) {
286
+ // add __hash__ field for inserts
287
+ sqlFields . push ( '"__hash__" TEXT UNIQUE' )
288
+ }
286
289
287
290
let definition = `CREATE TABLE IF NOT EXISTS ${ collection . tableName } (${ sqlFields . join ( ', ' ) } );`
288
291
0 commit comments