@@ -28,6 +28,7 @@ import { TimeSeriesOperations } from "./TimeSeries/TimeSeriesOperations";
2828import { TimeSeriesValuesHelper } from "./Session/TimeSeries/TimeSeriesValuesHelper" ;
2929
3030export class BulkInsertOperation {
31+ private _options : BulkInsertOptions ;
3132 private readonly _generateEntityIdOnTheClient : GenerateEntityIdOnTheClient ;
3233
3334 private readonly _requestExecutor : RequestExecutor ;
@@ -45,6 +46,7 @@ export class BulkInsertOperation {
4546 private readonly _timeSeriesBatchSize : number ;
4647
4748 private _concurrentCheck : number = 0 ;
49+ private _isInitialWrite : boolean = true ;
4850
4951 private _bulkInsertAborted : Promise < void > ;
5052 private _abortReject : Function ;
@@ -53,12 +55,15 @@ export class BulkInsertOperation {
5355 private _requestBodyStream : stream . PassThrough ;
5456 private _pipelineFinished : Promise < void > ;
5557
56- public constructor ( database : string , store : IDocumentStore ) {
58+ public constructor ( database : string , store : IDocumentStore , options ?: BulkInsertOptions ) {
5759 this . _conventions = store . conventions ;
5860 if ( StringUtil . isNullOrEmpty ( database ) ) {
5961 this . _throwNoDatabase ( ) ;
6062 }
6163 this . _requestExecutor = store . getRequestExecutor ( database ) ;
64+ this . _useCompression = options ? options . useCompression : false ;
65+
66+ this . _options = options ?? { } ;
6267
6368 this . _timeSeriesBatchSize = this . _conventions . bulkInsert . timeSeriesBatchSize ;
6469
@@ -310,7 +315,7 @@ export class BulkInsertOperation {
310315
311316 this . _requestBodyStream = new stream . PassThrough ( ) ;
312317 const bulkCommand =
313- new BulkInsertCommand ( this . _operationId , this . _requestBodyStream , this . _nodeTag ) ;
318+ new BulkInsertCommand ( this . _operationId , this . _requestBodyStream , this . _nodeTag , this . _options . skipOverwriteIfUnchanged ) ;
314319 bulkCommand . useCompression = this . _useCompression ;
315320
316321 const bulkCommandPromise = this . _requestExecutor . execute ( bulkCommand ) ;
@@ -787,19 +792,25 @@ export class BulkInsertCommand extends RavenCommand<void> {
787792 }
788793
789794 private readonly _stream : stream . Readable ;
795+ private _skipOverwriteIfUnchanged : boolean ;
790796 private readonly _id : number ;
791797 public useCompression : boolean ;
792798
793- public constructor ( id : number , stream : stream . Readable , nodeTag : string ) {
799+ public constructor ( id : number , stream : stream . Readable , nodeTag : string , skipOverwriteIfUnchanged : boolean ) {
794800 super ( ) ;
795801
796802 this . _stream = stream ;
797803 this . _id = id ;
798804 this . _selectedNodeTag = nodeTag ;
805+ this . _skipOverwriteIfUnchanged = skipOverwriteIfUnchanged ;
799806 }
800807
801808 public createRequest ( node : ServerNode ) : HttpRequestParameters {
802- const uri = node . url + "/databases/" + node . database + "/bulk_insert?id=" + this . _id ;
809+ const uri = node . url
810+ + "/databases/" + node . database
811+ + "/bulk_insert?id=" + this . _id
812+ + "&skipOverwriteIfUnchanged=" + ( this . _skipOverwriteIfUnchanged ? "true" : "false" ) ;
813+
803814 const headers = this . _headers ( ) . typeAppJson ( ) . build ( ) ;
804815 // TODO: useCompression ? new GzipCompressingEntity(_stream) : _stream);
805816 return {
@@ -815,3 +826,8 @@ export class BulkInsertCommand extends RavenCommand<void> {
815826 }
816827
817828}
829+
830+ export interface BulkInsertOptions {
831+ useCompression ?: boolean ;
832+ skipOverwriteIfUnchanged ?: boolean ;
833+ }
0 commit comments