@fluxbase/sdk 0.0.1-rc.31 → 0.0.1-rc.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3966,6 +3966,7 @@ var QueryBuilder = class {
3966
3966
  this.orderBys = [];
3967
3967
  this.singleRow = false;
3968
3968
  this.maybeSingleRow = false;
3969
+ this.operationType = "select";
3969
3970
  this.fetch = fetch2;
3970
3971
  this.table = table;
3971
3972
  }
@@ -3982,16 +3983,10 @@ var QueryBuilder = class {
3982
3983
  /**
3983
3984
  * Insert a single row or multiple rows
3984
3985
  */
3985
- async insert(data) {
3986
- const body = Array.isArray(data) ? data : data;
3987
- const response = await this.fetch.post(`/api/v1/tables/${this.table}`, body);
3988
- return {
3989
- data: response,
3990
- error: null,
3991
- count: Array.isArray(data) ? data.length : 1,
3992
- status: 201,
3993
- statusText: "Created"
3994
- };
3986
+ insert(data) {
3987
+ this.operationType = "insert";
3988
+ this.insertData = data;
3989
+ return this;
3995
3990
  }
3996
3991
  /**
3997
3992
  * Upsert (insert or update) rows (Supabase-compatible)
@@ -4028,32 +4023,17 @@ var QueryBuilder = class {
4028
4023
  /**
4029
4024
  * Update rows matching the filters
4030
4025
  */
4031
- async update(data) {
4032
- const queryString = this.buildQueryString();
4033
- const path = `/api/v1/tables/${this.table}${queryString}`;
4034
- const response = await this.fetch.patch(path, data);
4035
- return {
4036
- data: response,
4037
- error: null,
4038
- count: null,
4039
- status: 200,
4040
- statusText: "OK"
4041
- };
4026
+ update(data) {
4027
+ this.operationType = "update";
4028
+ this.updateData = data;
4029
+ return this;
4042
4030
  }
4043
4031
  /**
4044
4032
  * Delete rows matching the filters
4045
4033
  */
4046
- async delete() {
4047
- const queryString = this.buildQueryString();
4048
- const path = `/api/v1/tables/${this.table}${queryString}`;
4049
- await this.fetch.delete(path);
4050
- return {
4051
- data: null,
4052
- error: null,
4053
- count: null,
4054
- status: 204,
4055
- statusText: "No Content"
4056
- };
4034
+ delete() {
4035
+ this.operationType = "delete";
4036
+ return this;
4057
4037
  }
4058
4038
  /**
4059
4039
  * Equal to
@@ -4432,13 +4412,13 @@ var QueryBuilder = class {
4432
4412
  * { name: 'Alice', email: 'alice@example.com' },
4433
4413
  * { name: 'Bob', email: 'bob@example.com' },
4434
4414
  * { name: 'Charlie', email: 'charlie@example.com' }
4435
- * ]).execute()
4415
+ * ])
4436
4416
  * ```
4437
4417
  *
4438
4418
  * @category Batch Operations
4439
4419
  */
4440
4420
  async insertMany(rows) {
4441
- return this.insert(rows);
4421
+ return this.insert(rows).execute();
4442
4422
  }
4443
4423
  /**
4444
4424
  * Update multiple rows matching the filters (batch update)
@@ -4455,19 +4435,17 @@ var QueryBuilder = class {
4455
4435
  * const { data } = await client.from('products')
4456
4436
  * .eq('category', 'electronics')
4457
4437
  * .updateMany({ discount: 10, updated_at: new Date() })
4458
- * .execute()
4459
4438
  *
4460
4439
  * // Mark all pending orders as processing
4461
4440
  * const { data } = await client.from('orders')
4462
4441
  * .eq('status', 'pending')
4463
4442
  * .updateMany({ status: 'processing' })
4464
- * .execute()
4465
4443
  * ```
4466
4444
  *
4467
4445
  * @category Batch Operations
4468
4446
  */
4469
4447
  async updateMany(data) {
4470
- return this.update(data);
4448
+ return this.update(data).execute();
4471
4449
  }
4472
4450
  /**
4473
4451
  * Delete multiple rows matching the filters (batch delete)
@@ -4483,27 +4461,66 @@ var QueryBuilder = class {
4483
4461
  * await client.from('users')
4484
4462
  * .eq('active', false)
4485
4463
  * .deleteMany()
4486
- * .execute()
4487
4464
  *
4488
4465
  * // Delete old logs
4489
4466
  * await client.from('logs')
4490
4467
  * .lt('created_at', '2024-01-01')
4491
4468
  * .deleteMany()
4492
- * .execute()
4493
4469
  * ```
4494
4470
  *
4495
4471
  * @category Batch Operations
4496
4472
  */
4497
4473
  async deleteMany() {
4498
- return this.delete();
4474
+ return this.delete().execute();
4499
4475
  }
4500
4476
  /**
4501
4477
  * Execute the query and return results
4502
4478
  */
4503
4479
  async execute() {
4504
- const queryString = this.buildQueryString();
4505
- const path = `/api/v1/tables/${this.table}${queryString}`;
4506
4480
  try {
4481
+ if (this.operationType === "insert") {
4482
+ if (!this.insertData) {
4483
+ throw new Error("Insert data is required for insert operation");
4484
+ }
4485
+ const body = Array.isArray(this.insertData) ? this.insertData : this.insertData;
4486
+ const response = await this.fetch.post(`/api/v1/tables/${this.table}`, body);
4487
+ return {
4488
+ data: response,
4489
+ error: null,
4490
+ count: Array.isArray(this.insertData) ? this.insertData.length : 1,
4491
+ status: 201,
4492
+ statusText: "Created"
4493
+ };
4494
+ }
4495
+ if (this.operationType === "update") {
4496
+ if (!this.updateData) {
4497
+ throw new Error("Update data is required for update operation");
4498
+ }
4499
+ const queryString2 = this.buildQueryString();
4500
+ const path2 = `/api/v1/tables/${this.table}${queryString2}`;
4501
+ const response = await this.fetch.patch(path2, this.updateData);
4502
+ return {
4503
+ data: response,
4504
+ error: null,
4505
+ count: null,
4506
+ status: 200,
4507
+ statusText: "OK"
4508
+ };
4509
+ }
4510
+ if (this.operationType === "delete") {
4511
+ const queryString2 = this.buildQueryString();
4512
+ const path2 = `/api/v1/tables/${this.table}${queryString2}`;
4513
+ await this.fetch.delete(path2);
4514
+ return {
4515
+ data: null,
4516
+ error: null,
4517
+ count: null,
4518
+ status: 204,
4519
+ statusText: "No Content"
4520
+ };
4521
+ }
4522
+ const queryString = this.buildQueryString();
4523
+ const path = `/api/v1/tables/${this.table}${queryString}`;
4507
4524
  const data = await this.fetch.get(path);
4508
4525
  if (this.singleRow) {
4509
4526
  if (Array.isArray(data) && data.length === 0) {