imodel 0.20.0 → 0.20.1

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * imodel v0.20.0
2
+ * imodel v0.20.1
3
3
  * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
@@ -429,6 +429,26 @@ function createInterface (connPromise, baseTransaction) {
429
429
  }
430
430
  }
431
431
  const ci = {
432
+ async dbType() {
433
+ const conn = await connPromise;
434
+ return conn.dbType;
435
+ },
436
+ async dbVersion() {
437
+ const conn = await connPromise;
438
+ return conn.dbVersion(env);
439
+ },
440
+ async query(...values) {
441
+ const conn = await connPromise;
442
+ return conn.query(env, ...values);
443
+ },
444
+ async exec(...values) {
445
+ const conn = await connPromise;
446
+ return conn.exec(env, ...values);
447
+ },
448
+ async type(table) {
449
+ const conn = await connPromise;
450
+ return conn.type(env, table);
451
+ },
432
452
  async insert(table, data, keys, conflictTarget, conflictSet, conflictWhere) {
433
453
  const conn = await connPromise;
434
454
  return conn.insert(env, table.table, table.columns, data, keys, conflictTarget, conflictSet, conflictWhere);
@@ -2486,7 +2506,7 @@ function sort2column(sort, fieldColumns) {
2486
2506
  return sort.map(([f, d]) => [fieldColumns[f], d]);
2487
2507
  }
2488
2508
 
2489
- /** @import Connection from './index.mjs' */
2509
+ /** @import Connection from './index.mts' */
2490
2510
  /** @import { FieldDefine, Fields, Skip, TableDefine, FieldType, SelectItem, LockType, ConnectionInterface } from '../types' */
2491
2511
 
2492
2512
  /**
@@ -2687,7 +2707,7 @@ function find (sql, skip) {
2687
2707
  };
2688
2708
  }
2689
2709
 
2690
- /** @import Connection from './index.mjs' */
2710
+ /** @import Connection from './index.mts' */
2691
2711
  /** @import { Environment, TableDefine, Skip, SelectItem, ConnectionInterface, BaseEnvironment } from '../types' */
2692
2712
 
2693
2713
  /**
@@ -3578,50 +3598,22 @@ var index$1 = /*#__PURE__*/Object.freeze({
3578
3598
  upsert: upsert
3579
3599
  });
3580
3600
 
3581
- /** @import { Wheres } from '../Where.mjs' */
3582
- /** @import { SetValue } from '../set.mjs' */
3583
- /** @import { Environment, TableValue } from '../types' */
3584
- /** @import { Fields, FieldValue, IndexOptions, MainFieldType, TableDefine } from '../types/table' */
3585
- /** @import { Queryable } from '../types/options' */
3586
- /** @import { Column, ColumnOptions } from '../types/column' */
3587
- /** @import { Action, ConnectionInterface, DBTable, IConnection, Savepoint, Skip, TableType, TransactionHandler } from '../types/connection' */
3588
-
3601
+ /* eslint-disable max-lines */
3589
3602
 
3590
- /**
3591
- * @template {{}} [E={}]
3592
- */
3593
3603
  class Connection {
3594
- /** @type {Environment<E>} */
3595
3604
  #env;
3596
- /** @type {() => Promise<IConnection<E>>} */
3597
3605
  #getConnection;
3598
- /** @type {E?} */
3599
3606
  #baseTransaction;
3600
- /**
3601
- *
3602
- * @param {PromiseLike<IConnection<E>> | IConnection<E>} connection
3603
- * @param {E?} [transaction]
3604
- */
3605
3607
  constructor(connection, transaction = null) {
3606
3608
  this.#baseTransaction = transaction;
3607
3609
  const getConnection = async () => connection;
3608
3610
  this.#getConnection = getConnection;
3609
3611
  [this.#interface, this.#env] = createInterface(connection, transaction);
3610
3612
  }
3611
- /** @type {ConnectionInterface} */
3612
3613
  #interface;
3613
- /**
3614
- *
3615
- * @returns {Connection<E>}
3616
- */
3617
3614
  clone() {
3618
3615
  return new Connection(this.#getConnection(), this.#baseTransaction);
3619
3616
  }
3620
- /**
3621
- * @template T
3622
- * @param {Action<T>} action
3623
- * @returns {Promise<T>}
3624
- */
3625
3617
  async call(action) {
3626
3618
  const env = {
3627
3619
  isDevelopment,
@@ -3638,66 +3630,21 @@ class Connection {
3638
3630
  let conn = null;
3639
3631
  return action.invoke(() => conn ||= connect(), this, env);
3640
3632
  }
3641
-
3642
- /** @return {Promise<string>} */
3643
3633
  async dbType() {
3644
- const conn = await this.#getConnection();
3645
- return conn.dbType;
3634
+ return this.#interface.dbType();
3646
3635
  }
3647
- /** @return {Promise<string>} */
3648
3636
  async dbVersion() {
3649
- const conn = await this.#getConnection();
3650
- return conn.dbVersion(this.#env);
3637
+ return this.#interface.dbVersion();
3651
3638
  }
3652
- /**
3653
- *
3654
- * @param {...any} values
3655
- * @returns {Promise<any[]>}
3656
- */
3657
3639
  async query(...values) {
3658
- const conn = await this.#getConnection();
3659
- return conn.query(this.#env, ...values);
3640
+ return this.#interface.query(...values);
3660
3641
  }
3661
- /**
3662
- *
3663
- * @param {...any} values
3664
- * @returns {Promise<number>}
3665
- */
3666
3642
  async exec(...values) {
3667
- const conn = await this.#getConnection();
3668
- return conn.exec(this.#env, ...values);
3643
+ return this.#interface.exec(...values);
3669
3644
  }
3670
- /**
3671
- *
3672
- * @param {string} table
3673
- * @returns {Promise<TableType?>}
3674
- */
3675
3645
  async type(table) {
3676
- const conn = await this.#getConnection();
3677
- return conn.type(this.#env, table);
3646
+ return this.#interface.type(table);
3678
3647
  }
3679
- /**
3680
- * @template T
3681
- * @overload
3682
- * @param {Build<T>} build
3683
- * @param {object} data
3684
- * @param {object | boolean} [saved]
3685
- * @returns {T}
3686
- */
3687
- /**
3688
- * @template {Fields} T
3689
- * @overload
3690
- * @param {TableDefine<T>} table
3691
- * @param {object} data
3692
- * @param {object | boolean} [saved]
3693
- * @returns {FieldValue<T>}
3694
- */
3695
- /**
3696
- * @param {Build | TableDefine} p
3697
- * @param {object} data
3698
- * @param {object | boolean} [saved]
3699
- * @returns {any}
3700
- */
3701
3648
  build(p, data, saved) {
3702
3649
  if (typeof p[Build] === 'function') {
3703
3650
  return p[Build](data, saved || false, this.#env);
@@ -3712,619 +3659,227 @@ class Connection {
3712
3659
  ...saved
3713
3660
  };
3714
3661
  }
3715
- /**
3716
- * @deprecated
3717
- * @template {TableDefine} T
3718
- * @overload
3719
- * @param {T} model
3720
- * @param {object[]} list
3721
- * @returns {Promise<TableValue<T>[]>}
3722
- */
3723
- /**
3724
- * @deprecated
3725
- * @template {TableDefine} T
3726
- * @overload
3727
- * @param {T} model
3728
- * @param {object} value
3729
- * @returns {Promise<T extends Build<infer R> ? R : TableValue<T>>}
3730
- */
3731
- /**
3732
- * @deprecated
3733
- * @template {TableDefine} T
3734
- * @overload
3735
- * @param {T} model
3736
- * @param {object | object[]} value
3737
- * @returns {Promise<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>}
3738
- */
3739
- /**
3740
- * @deprecated
3741
- * @template {TableDefine} T
3742
- * @param {T} model
3743
- * @param {object | object[]} p
3744
- * @param {Skip} [skip]
3745
- * @returns {Promise<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>}
3746
- */
3662
+ /** @deprecated */
3663
+
3664
+ /** @deprecated */
3665
+
3666
+ /** @deprecated */
3667
+
3668
+ /** @deprecated */
3747
3669
  async create(model, p, skip) {
3748
3670
  return this.call(create(model, p, skip));
3749
3671
  }
3750
- /**
3751
- *
3752
- * @deprecated
3753
- * @template {TableDefine} T
3754
- * @param {T} sql
3755
- * @param {string[]} fields
3756
- * @param {Skip} [skip]
3757
- * @returns {Promise<T extends TableDefine<infer F> ? FieldValue<F>[] : never>}
3758
- */
3672
+ /** @deprecated */
3759
3673
  async search(sql, fields, skip) {
3760
3674
  return this.call(search(sql, fields, skip));
3761
3675
  }
3762
- /**
3763
- * @deprecated
3764
- * @template {TableDefine} T
3765
- * @param {T} sql
3766
- * @param {Skip} [skip]
3767
- * @returns {Promise<T extends Build<infer R > ? R[] : T extends TableDefine<infer F> ? FieldValue<F>[] : never>}
3768
- */
3676
+ /** @deprecated */
3769
3677
  async find(sql, skip) {
3770
3678
  return this.call(find(sql, skip));
3771
3679
  }
3772
- /**
3773
- *
3774
- * @deprecated
3775
- * @template {TableDefine} T
3776
- * @param {T} sql
3777
- * @param {Skip} [skip]
3778
- * @returns {Promise<T extends Build<infer R > ? R : T extends TableDefine<infer F> ? FieldValue<F> : never>}
3779
- */
3680
+ /** @deprecated */
3780
3681
  async first(sql, skip) {
3781
3682
  return this.call(first(sql, skip));
3782
3683
  }
3783
- /**
3784
- * @deprecated
3785
- * @template T
3786
- * @param {TableDefine} model
3787
- * @param {T} data
3788
- * @param {Record<string, any>?} [newData]
3789
- * @param {Skip} [skip]
3790
- * @returns {Promise<(T extends Save ? T : object)?>}
3791
- */
3684
+ /** @deprecated */
3792
3685
  async save(model, data, newData, skip) {
3793
3686
  return this.call(save(model, data, newData, skip));
3794
3687
  }
3795
- /**
3796
- *
3797
- * @deprecated
3798
- * @template T
3799
- * @param {TableDefine} tableDef
3800
- * @param {T} data
3801
- * @returns {Promise<(T extends Destroy ? T : object)?>}
3802
- */
3688
+ /** @deprecated */
3803
3689
  async completelyDestroy(tableDef, data) {
3804
3690
  return this.call(completelyDestroy(tableDef, data));
3805
3691
  }
3806
- /**
3807
- *
3808
- * @deprecated
3809
- * @template {object} T
3810
- * @param {TableDefine} tableDef
3811
- * @param {T} data
3812
- * @param {Record<string, SetValue>} value
3813
- * @returns {Promise<(T extends PseudoDestroy ? T : object)?>}
3814
- */
3692
+ /** @deprecated */
3815
3693
  async pseudoDestroy(tableDef, data, value) {
3816
3694
  return this.call(pseudoDestroy(tableDef, data, value));
3817
3695
  }
3818
- /**
3819
- * @deprecated
3820
- * @template {Destroy & PseudoDestroy} T
3821
- * @overload
3822
- * @param {TableDefine} table
3823
- * @param {T} data
3824
- * @param {Record<string, any> | boolean} [update]
3825
- * @returns {Promise<T?>}
3826
- */
3827
- /**
3828
- * @deprecated
3829
- * @template {Destroy & PseudoDestroy} T
3830
- * @overload
3831
- * @param {TableDefine} table
3832
- * @param {T} data
3833
- * @param {Record<string, any> | boolean} [update]
3834
- * @returns {Promise<T | object | null>}
3835
- */
3836
- /**
3837
- * @deprecated
3838
- * @overload
3839
- * @param {TableDefine} table
3840
- * @param {any} data
3841
- * @param {Record<string, any> | boolean} [update]
3842
- * @returns {Promise<object?>}
3843
- */
3844
- /**
3845
- * @deprecated
3846
- * @param {TableDefine} tableDef
3847
- * @param {any} data
3848
- * @param {Record<string, any> | boolean} [update]
3849
- * @returns {Promise<object?>}
3850
- */
3696
+ /** @deprecated */
3697
+
3698
+ /** @deprecated */
3699
+
3700
+ /** @deprecated */
3701
+
3702
+ /** @deprecated */
3851
3703
  async destroy(tableDef, data, update) {
3852
3704
  return this.call(destroy(tableDef, data, update));
3853
3705
  }
3854
- /**
3855
- * @deprecated
3856
- * @param {Queryable} queryable
3857
- * @param {Record<string, SetValue> | boolean} [update]
3858
- * @returns {Promise<number>}
3859
- */
3706
+ /** @deprecated */
3860
3707
  async destroyMany(queryable, update) {
3861
3708
  return this.call(destroyMany(queryable, update));
3862
3709
  }
3863
- /**
3864
- * @deprecated
3865
- * @template {object} T
3866
- * @overload
3867
- * @param {TableDefine} tableDefine
3868
- * @param {T} data
3869
- * @param {boolean} [ignoreConflict]
3870
- * @returns {Promise<T>}
3871
- */
3872
- /**
3873
- * @deprecated
3874
- * @template {object} T
3875
- * @overload
3876
- * @param {TableDefine} tableDefine
3877
- * @param {T[]} data
3878
- * @param {boolean} [ignoreConflict]
3879
- * @returns {Promise<T[]>}
3880
- */
3881
- /**
3882
- * @deprecated
3883
- * @template {object} T
3884
- * @overload
3885
- * @param {TableDefine} tableDefine
3886
- * @param {T} data
3887
- * @param {string[]} [keys]
3888
- * @param {boolean} [ignoreConflict]
3889
- * @returns {Promise<T>}
3890
- */
3891
- /**
3892
- * @deprecated
3893
- * @template {object} T
3894
- * @overload
3895
- * @param {TableDefine} tableDefine
3896
- * @param {T[]} data
3897
- * @param {string[]} [keys]
3898
- * @param {boolean} [ignoreConflict]
3899
- * @returns {Promise<T[]>}
3900
- */
3901
- /**
3902
- * @deprecated
3903
- * @template {object} T
3904
- * @overload
3905
- * @param {TableDefine} tableDefine
3906
- * @param {T} data
3907
- * @param {string[] | boolean} [keys]
3908
- * @param {boolean} [ignoreConflict]
3909
- * @returns {Promise<T>}
3910
- */
3911
- /**
3912
- * @deprecated
3913
- * @template {object} T
3914
- * @overload
3915
- * @param {TableDefine} tableDefine
3916
- * @param {T[]} data
3917
- * @param {string[] | boolean} [keys]
3918
- * @param {boolean} [ignoreConflict]
3919
- * @returns {Promise<T[]>}
3920
- */
3921
- /**
3922
- * @deprecated
3923
- * @template {object} T
3924
- * @overload
3925
- * @param {TableDefine} tableDefine
3926
- * @param {T | T[]} data
3927
- * @param {string[] | boolean} [keys]
3928
- * @param {boolean} [ignoreConflict]
3929
- * @returns {Promise<T | T[]>}
3930
- */
3931
- /**
3932
- * @deprecated
3933
- * @template {object} T
3934
- * @param {TableDefine} table
3935
- * @param {T | T[]} data
3936
- * @param {string[] | boolean} [keys]
3937
- * @param {boolean} [ignoreConflict]
3938
- * @returns {Promise<T | T[]>}
3939
- */
3710
+ /** @deprecated */
3711
+
3712
+ /** @deprecated */
3713
+
3714
+ /** @deprecated */
3715
+
3716
+ /** @deprecated */
3717
+
3718
+ /** @deprecated */
3719
+
3720
+ /** @deprecated */
3721
+
3722
+ /** @deprecated */
3723
+
3724
+ /** @deprecated */
3940
3725
  async insert(table, data, keys, ignoreConflict) {
3941
3726
  // @ts-ignore
3942
3727
  return this.call(insert(table, data, keys, ignoreConflict));
3943
3728
  }
3944
- /**
3945
- * @deprecated
3946
- * @template {object} T
3947
- * @overload
3948
- * @param {TableDefine} tableDefine
3949
- * @param {T} data
3950
- * @param {Record<string, SetValue>} [conflictSet]
3951
- * @returns {Promise<T>}
3952
- */
3953
- /**
3954
- * @deprecated
3955
- * @template {object} T
3956
- * @overload
3957
- * @param {TableDefine} tableDefine
3958
- * @param {T[]} data
3959
- * @param {Record<string, SetValue>} [conflictSet]
3960
- * @returns {Promise<T[]>}
3961
- */
3962
- /**
3963
- * @deprecated
3964
- * @template {object} T
3965
- * @overload
3966
- * @param {TableDefine} tableDefine
3967
- * @param {T} data
3968
- * @param {null | string[]} [keys]
3969
- * @param {Record<string, SetValue>} [conflictSet]
3970
- * @returns {Promise<T>}
3971
- */
3972
- /**
3973
- * @deprecated
3974
- * @template {object} T
3975
- * @overload
3976
- * @param {TableDefine} tableDefine
3977
- * @param {T[]} data
3978
- * @param {null | string[]} [keys]
3979
- * @param {Record<string, SetValue>} [conflictSet]
3980
- * @returns {Promise<T[]>}
3981
- */
3982
- /**
3983
- * @deprecated
3984
- * @template {object} T
3985
- * @overload
3986
- * @param {TableDefine} tableDefine
3987
- * @param {T} data
3988
- * @param {null | string[]} [keys]
3989
- * @param {string[] | boolean} [conflictKeys]
3990
- * @param {Record<string, SetValue>} [conflictSet]
3991
- * @returns {Promise<T>}
3992
- */
3993
- /**
3994
- * @deprecated
3995
- * @template {object} T
3996
- * @overload
3997
- * @param {TableDefine} tableDefine
3998
- * @param {T[]} data
3999
- * @param {null | string[]} [keys]
4000
- * @param {string[] | boolean} [conflictKeys]
4001
- * @param {Record<string, SetValue>} [conflictSet]
4002
- * @returns {Promise<T[]>}
4003
- */
4004
- /**
4005
- * @deprecated
4006
- * @template {object} T
4007
- * @overload
4008
- * @param {TableDefine} tableDefine
4009
- * @param {T} data
4010
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
4011
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
4012
- * @param {Record<string, SetValue>} [conflictSet]
4013
- * @returns {Promise<T>}
4014
- */
4015
- /**
4016
- * @deprecated
4017
- * @template {object} T
4018
- * @overload
4019
- * @param {TableDefine} tableDefine
4020
- * @param {T[]} data
4021
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
4022
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
4023
- * @param {Record<string, SetValue>} [conflictSet]
4024
- * @returns {Promise<T[]>}
4025
- */
4026
- /**
4027
- * @deprecated
4028
- * @template {object} T
4029
- * @overload
4030
- * @param {TableDefine} tableDefine
4031
- * @param {T | T[]} data
4032
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
4033
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
4034
- * @param {Record<string, SetValue>} [conflictSet]
4035
- * @returns {Promise<T | T[]>}
4036
- */
4037
- /**
4038
- * @deprecated
4039
- * @template {object} T
4040
- * @param {TableDefine} tableDefine
4041
- * @param {T | T[]} data
4042
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
4043
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
4044
- * @param {Record<string, SetValue>} [conflictSet]
4045
- * @returns {Promise<T | T[]>}
4046
- */
3729
+ /** @deprecated */
3730
+
3731
+ /** @deprecated */
3732
+
3733
+ /** @deprecated */
3734
+
3735
+ /** @deprecated */
3736
+
3737
+ /** @deprecated */
3738
+
3739
+ /** @deprecated */
3740
+
3741
+ /** @deprecated */
3742
+
3743
+ /** @deprecated */
3744
+
3745
+ /** @deprecated */
3746
+
3747
+ /** @deprecated */
4047
3748
  async upsert(tableDefine, data, keys, conflictKeys, conflictSet) {
4048
3749
  // @ts-ignore
4049
3750
  return this.call(
4050
3751
  // @ts-ignore
4051
3752
  upsert(tableDefine, data, keys, conflictKeys, conflictSet));
4052
3753
  }
4053
- /**
4054
- * @deprecated
4055
- * @param {TableDefine} table
4056
- * @param {Record<string, any>} update
4057
- * @param {Wheres?} [where]
4058
- * @param {boolean | Skip} [skip]
4059
- * @returns {Promise<number>}
4060
- */
3754
+ /** @deprecated */
4061
3755
  async update(table, update$1, where, skip) {
4062
3756
  return this.call(update(table, update$1, where, skip));
4063
3757
  }
4064
- /**
4065
- * @deprecated
4066
- * @template {Fields<MainFieldType>} T
4067
- * @param {TableDefine<T>} table
4068
- * @param {Record<string, any>} update
4069
- * @param {string[]?} [returning]
4070
- * @param {Wheres?} [where]
4071
- * @param {boolean | Skip} [skip]
4072
- * @returns {Promise<any[]>}
4073
- */
3758
+ /** @deprecated */
4074
3759
  async updateReturn(table, update, returning, where, skip) {
4075
3760
  return this.call(updateReturn(table, update, returning, where, skip));
4076
3761
  }
4077
- /**
4078
- * @deprecated
4079
- * @param {TableDefine} table
4080
- * @param {string[]} pKeys
4081
- * @param {string[]} setKeys
4082
- * @param {Record<string, any>[]} list
4083
- * @param {boolean | Skip} [skip]
4084
- * @returns {Promise<number>}
4085
- */
3762
+ /** @deprecated */
4086
3763
  async updateMany(table, pKeys, setKeys, list, skip) {
4087
3764
  return this.call(updateList(table, pKeys, setKeys, list, skip));
4088
3765
  }
4089
- /**
4090
- * @deprecated
4091
- * @template {Fields<MainFieldType>} T
4092
- * @param {TableDefine<T>} table
4093
- * @param {string[]} pKeys
4094
- * @param {string[]} setKeys
4095
- * @param {Record<string, any>[]} list
4096
- * @param {string[]?} [returning]
4097
- * @param {boolean | Skip} [skip]
4098
- * @returns {Promise<any[]>}
4099
- */
3766
+ /** @deprecated */
4100
3767
  async updateManyReturn(table, pKeys, setKeys, list, returning, skip) {
4101
3768
  return this.call(updateListReturn(table, pKeys, setKeys, list, returning, skip));
4102
3769
  }
4103
- /**
4104
- * @deprecated
4105
- * @param {TableDefine} table
4106
- * @param {Wheres?} [where]
4107
- * @returns {Promise<number>}
4108
- */
3770
+ /** @deprecated */
4109
3771
  async delete(table, where) {
4110
3772
  return this.call(_delete(table, where));
4111
3773
  }
4112
-
4113
- /**
4114
- * @deprecated
4115
- * @template {Fields<MainFieldType>} T
4116
- * @param {TableDefine<T>} table
4117
- * @param {string[]?} [returning]
4118
- * @param {Wheres?} [where]
4119
- * @returns {Promise<any[]>}
4120
- */
3774
+ /** @deprecated */
4121
3775
  async deleteReturn(table, returning, where) {
4122
3776
  return this.call(deleteReturn(table, returning, where));
4123
3777
  }
4124
- /**
4125
- *
4126
- * @deprecated
4127
- * @param {Queryable} queryable
4128
- * @returns {Promise<number>}
4129
- */
3778
+ /** @deprecated */
4130
3779
  async count(queryable) {
4131
3780
  return this.call(count(queryable));
4132
3781
  }
4133
- /**
4134
- * @deprecated
4135
- * @param {Queryable} queryable
4136
- * @returns {Promise<any[]>}
4137
- */
3782
+ /** @deprecated */
4138
3783
  async select(queryable) {
4139
3784
  return this.call(select(queryable));
4140
3785
  }
4141
- /**
4142
- * @param {string} table
4143
- * @param {string} column
4144
- * @param {string} type
4145
- * @param {ColumnOptions<any>} options
4146
- * @returns {Promise<number>}
4147
- */
4148
3786
  async addColumn(table, column, type, options) {
4149
3787
  const conn = await this.#getConnection();
4150
3788
  return conn.addColumn(this.#env, table, column, type, setDefaultOptions(options));
4151
3789
  }
4152
- /**
4153
- * @param {string} table
4154
- * @param {string} column
4155
- * @param {string} type
4156
- * @param {ColumnOptions<any>} options
4157
- * @returns {Promise<number>}
4158
- */
4159
3790
  async changeColumn(table, column, type, options) {
4160
3791
  const conn = await this.#getConnection();
4161
3792
  return conn.changeColumn(this.#env, table, column, type, setDefaultOptions(options));
4162
3793
  }
4163
- /**
4164
- * @param {string} table
4165
- * @param {string} column
4166
- * @param {boolean} nullable
4167
- * @returns {Promise<number>}
4168
- */
4169
3794
  async changeColumnNull(table, column, nullable) {
4170
3795
  const conn = await this.#getConnection();
4171
3796
  return conn.changeColumnNull(this.#env, table, column, nullable);
4172
3797
  }
4173
- /**
4174
- * @param {string} table
4175
- * @param {string} column
4176
- * @returns {Promise<number>}
4177
- */
4178
3798
  async dropColumn(table, column) {
4179
3799
  const conn = await this.#getConnection();
4180
3800
  return conn.dropColumn(this.#env, table, column);
4181
3801
  }
4182
- /**
4183
- * @param {string} table
4184
- * @param {string} column
4185
- * @param {string} newName
4186
- * @returns {Promise<number>}
4187
- */
4188
3802
  async renameColumn(table, column, newName) {
4189
3803
  const conn = await this.#getConnection();
4190
3804
  return conn.renameColumn(this.#env, table, column, newName);
4191
3805
  }
4192
- /**
4193
- * @param {string} table
4194
- * @param {string} name
4195
- * @param {string[]} fields
4196
- * @param {IndexOptions} [options]
4197
- * @returns {Promise<number>}
4198
- */
4199
3806
  async addIndex(table, name, fields, options = {}) {
4200
3807
  const conn = await this.#getConnection();
4201
3808
  return conn.addIndex(this.#env, table, name, fields, options);
4202
3809
  }
4203
- /**
4204
- * @param {string} table
4205
- * @param {string} name
4206
- * @returns {Promise<number>}
4207
- */
4208
3810
  async dropIndex(table, name) {
4209
3811
  const conn = await this.#getConnection();
4210
3812
  return conn.dropIndex(this.#env, table, name);
4211
3813
  }
4212
- /**
4213
- * @param {string} table
4214
- * @param {Column<any>[]} fields
4215
- * @returns {Promise<number>}
4216
- */
4217
3814
  async createTable(table, fields) {
4218
3815
  const conn = await this.#getConnection();
4219
3816
  return conn.createTable(this.#env, table, fields.map(setDefaultOptions));
4220
3817
  }
4221
- /**
4222
- * @param {string} table
4223
- * @returns {Promise<number>}
4224
- */
4225
3818
  async dropTable(table) {
4226
3819
  const conn = await this.#getConnection();
4227
3820
  return conn.dropTable(this.#env, table);
4228
3821
  }
4229
- /**
4230
- * @param {string} table
4231
- * @param {string} newName
4232
- * @returns {Promise<number>}
4233
- */
4234
3822
  async renameTable(table, newName) {
4235
3823
  const conn = await this.#getConnection();
4236
3824
  return conn.renameTable(this.#env, table, newName);
4237
3825
  }
4238
- /**
4239
- * @template T
4240
- * @param {(signal: AbortSignal) => PromiseLike<T> | T} fn
4241
- * @returns {Promise<T>}
4242
- */
4243
- async #transaction(fn) {
4244
- return this.#interface.transaction(fn);
4245
- }
4246
- abort() {
4247
- return this.#interface.abort();
4248
- }
4249
- /**
4250
- * @returns {Promise<Savepoint>}
4251
- */
4252
- async savepoint() {
4253
- return this.#interface.savepoint();
4254
- }
4255
- [Symbol.dispose]() {
4256
- this.#interface.abort();
4257
- }
4258
- /**
4259
- * @param {string} table
4260
- * @returns {Promise<DBTable?>}
4261
- */
4262
3826
  async loadTable(table) {
4263
3827
  const conn = await this.#getConnection();
4264
3828
  return conn.loadTables(this.#env, [table]).then(v => v[0] || null);
4265
3829
  }
4266
- /**
4267
- * @param {string[]} tables
4268
- * @returns {Promise<DBTable[]>}
4269
- */
4270
3830
  async loadTables(tables) {
4271
3831
  const conn = await this.#getConnection();
4272
3832
  return conn.loadTables(this.#env, tables);
4273
3833
  }
4274
- /**
4275
- * @param {TableDefine | DBTable} table
4276
- * @returns {Promise<void>}
4277
- */
4278
3834
  async syncTable(table) {
4279
3835
  const conn = await this.#getConnection();
4280
3836
  return conn.syncTables(this.#env, table2db([table]));
4281
3837
  }
4282
- /**
4283
- * @param {(TableDefine | DBTable)[]} tables
4284
- * @returns {Promise<void>}
4285
- */
4286
3838
  async syncTables(tables) {
4287
3839
  const conn = await this.#getConnection();
4288
3840
  return conn.syncTables(this.#env, table2db(tables));
4289
3841
  }
3842
+ async #transaction(fn) {
3843
+ return this.#interface.transaction(fn);
3844
+ }
3845
+ abort() {
3846
+ return this.#interface.abort();
3847
+ }
3848
+ async savepoint() {
3849
+ return this.#interface.savepoint();
3850
+ }
3851
+ [Symbol.dispose]() {
3852
+ this.#interface.abort();
3853
+ }
4290
3854
  /**
4291
3855
  * @template T
4292
3856
  * @overload
4293
- * @param {(t: Connection) => PromiseLike<T> | T} fn
3857
+ * @param {Action<T> |((t: Connection, signal: AbortSignal) => PromiseLike<T> | T)} fn
4294
3858
  * @returns {Promise<T>}
4295
3859
  */
4296
- /**
4297
- * @overload
4298
- * @returns {TransactionHandler}
4299
- */
4300
- /**
4301
- *
4302
- * @template T
4303
- * @param {(t: Connection, signal: AbortSignal) => PromiseLike<T> | T} [fn]
4304
- * @returns {Promise<T> | TransactionHandler}
4305
- */
4306
- /**
4307
- *
4308
- * @template T
4309
- * @param {(t: Connection, signal: AbortSignal) => PromiseLike<T> | T} [fn]
4310
- * @returns {Promise<T> | TransactionHandler}
4311
- */
3860
+
4312
3861
  transaction(fn) {
3862
+ if (Array.isArray(fn)) {
3863
+ return this.#transaction(signal => Promise.all(fn.map(v => {
3864
+ if (typeof v === 'function') {
3865
+ return v(this, signal);
3866
+ }
3867
+ return this.call(v);
3868
+ })));
3869
+ }
4313
3870
  if (typeof fn === 'function') {
4314
3871
  return this.#transaction(signal => fn(this, signal));
4315
3872
  }
4316
- /** @type {(p: AbortSignal) => void} */
3873
+ if (fn && typeof fn === 'object') {
3874
+ return this.#transaction(() => this.call(fn));
3875
+ }
4317
3876
  let throwAborted = () => {};
4318
- /** @type {Promise<void>} */
4319
3877
  const abortedPromise = new Promise((_, r) => {
4320
3878
  throwAborted = r;
4321
3879
  });
4322
3880
  abortedPromise.catch(() => {});
4323
- /** @type {() => void} */
4324
3881
  let commit = () => {};
4325
- /** @type {(e?: any) => void} */
4326
3882
  let rollback = () => {};
4327
- /** @type {Promise<void>} */
4328
3883
  const donePromise = new Promise((r1, r2) => {
4329
3884
  commit = r1;
4330
3885
  rollback = r2;
@@ -4337,7 +3892,7 @@ class Connection {
4337
3892
  }
4338
3893
  return donePromise;
4339
3894
  }).then(() => {}, () => {});
4340
- const handler = /** @type {TransactionHandler} */[abortedPromise, () => {
3895
+ const handler = [abortedPromise, () => {
4341
3896
  commit();
4342
3897
  return dbiPromise;
4343
3898
  }, e => {
@@ -5652,7 +5207,7 @@ function toBool(v) {
5652
5207
  return !falseValues.has(v.toLowerCase());
5653
5208
  }
5654
5209
 
5655
- /** @import { FieldDefine, Fields, LockType, Options, Queryable, Select } from './types' */
5210
+ /** @import { Action, FieldDefine, Fields, LockType, Options, Queryable, Select, Skip, TableConnect } from './types' */
5656
5211
  /** @import { WhereValue, Wheres } from './Where.mjs' */
5657
5212
  /**
5658
5213
  *
@@ -5710,6 +5265,7 @@ function selectFn(fn, select, newSelect) {
5710
5265
  * @template {object} [TB=object]
5711
5266
  * @typedef {object} QueryOptions
5712
5267
  * @property {string} [table]
5268
+ * @property {TableConnect?} [connect]
5713
5269
  * @property {T} fields
5714
5270
  * @property {string} [pseudo]
5715
5271
  * @property {((a: object, b?: object | boolean) => TB)?} [build]
@@ -5739,6 +5295,8 @@ class Query extends Subquery {
5739
5295
  }
5740
5296
  /** @readonly @type {string | undefined} */
5741
5297
 
5298
+ /** @readonly @type {TableConnect | null | undefined} */
5299
+
5742
5300
  /** @readonly @type {T} */
5743
5301
 
5744
5302
  /** @readonly @type {string} */
@@ -5766,6 +5324,7 @@ class Query extends Subquery {
5766
5324
  super();
5767
5325
  if (options instanceof Query) {
5768
5326
  this.table = options.table;
5327
+ this.connect = options.connect;
5769
5328
  this.fields = options.fields;
5770
5329
  this.pseudo = options.pseudo;
5771
5330
  this.#build = noBuild ? null : options.#build;
@@ -5776,11 +5335,13 @@ class Query extends Subquery {
5776
5335
  } else {
5777
5336
  const {
5778
5337
  table,
5338
+ connect,
5779
5339
  fields,
5780
5340
  pseudo,
5781
5341
  build
5782
5342
  } = options;
5783
5343
  this.table = table;
5344
+ this.connect = connect;
5784
5345
  this.fields = fields;
5785
5346
  this.pseudo = typeof pseudo === 'string' ? pseudo : '';
5786
5347
  this.#build = typeof build === 'function' ? build : null;