@supabase/postgrest-js 3.0.0-next.17 → 3.0.0-next.18

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.d.cts CHANGED
@@ -2876,35 +2876,350 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
2876
2876
  head?: boolean;
2877
2877
  count?: 'exact' | 'planned' | 'estimated' | (string & {});
2878
2878
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], ResultOne[], RelationName, Relationships, 'GET'>;
2879
+ /**
2880
+ * Perform an INSERT into the table or view.
2881
+ *
2882
+ * By default, inserted rows are not returned. To return it, chain the call
2883
+ * with `.select()`.
2884
+ *
2885
+ * @param values - The values to insert. Pass an object to insert a single row
2886
+ * or an array to insert multiple rows.
2887
+ *
2888
+ * @param options - Named parameters
2889
+ *
2890
+ * @param options.count - Count algorithm to use to count inserted rows.
2891
+ *
2892
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
2893
+ * hood.
2894
+ *
2895
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
2896
+ * statistics under the hood.
2897
+ *
2898
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
2899
+ * numbers.
2900
+ *
2901
+ * @param options.defaultToNull - Make missing fields default to `null`.
2902
+ * Otherwise, use the default value for the column. Only applies for bulk
2903
+ * inserts.
2904
+ *
2905
+ * @category Database
2906
+ *
2907
+ * @example Create a record
2908
+ * ```ts
2909
+ * const { error } = await supabase
2910
+ * .from('countries')
2911
+ * .insert({ id: 1, name: 'Mordor' })
2912
+ * ```
2913
+ *
2914
+ * @exampleSql Create a record
2915
+ * ```sql
2916
+ * create table
2917
+ * countries (id int8 primary key, name text);
2918
+ * ```
2919
+ *
2920
+ * @exampleResponse Create a record
2921
+ * ```json
2922
+ * {
2923
+ * "status": 201,
2924
+ * "statusText": "Created"
2925
+ * }
2926
+ * ```
2927
+ *
2928
+ * @example Create a record and return it
2929
+ * ```ts
2930
+ * const { data, error } = await supabase
2931
+ * .from('countries')
2932
+ * .insert({ id: 1, name: 'Mordor' })
2933
+ * .select()
2934
+ * ```
2935
+ *
2936
+ * @exampleSql Create a record and return it
2937
+ * ```sql
2938
+ * create table
2939
+ * countries (id int8 primary key, name text);
2940
+ * ```
2941
+ *
2942
+ * @exampleResponse Create a record and return it
2943
+ * ```json
2944
+ * {
2945
+ * "data": [
2946
+ * {
2947
+ * "id": 1,
2948
+ * "name": "Mordor"
2949
+ * }
2950
+ * ],
2951
+ * "status": 201,
2952
+ * "statusText": "Created"
2953
+ * }
2954
+ * ```
2955
+ *
2956
+ * @exampleDescription Bulk create
2957
+ * A bulk create operation is handled in a single transaction.
2958
+ * If any of the inserts fail, none of the rows are inserted.
2959
+ *
2960
+ * @example Bulk create
2961
+ * ```ts
2962
+ * const { error } = await supabase
2963
+ * .from('countries')
2964
+ * .insert([
2965
+ * { id: 1, name: 'Mordor' },
2966
+ * { id: 1, name: 'The Shire' },
2967
+ * ])
2968
+ * ```
2969
+ *
2970
+ * @exampleSql Bulk create
2971
+ * ```sql
2972
+ * create table
2973
+ * countries (id int8 primary key, name text);
2974
+ * ```
2975
+ *
2976
+ * @exampleResponse Bulk create
2977
+ * ```json
2978
+ * {
2979
+ * "error": {
2980
+ * "code": "23505",
2981
+ * "details": "Key (id)=(1) already exists.",
2982
+ * "hint": null,
2983
+ * "message": "duplicate key value violates unique constraint \"countries_pkey\""
2984
+ * },
2985
+ * "status": 409,
2986
+ * "statusText": "Conflict"
2987
+ * }
2988
+ * ```
2989
+ */
2879
2990
  insert<Row extends (Relation$1 extends {
2880
2991
  Insert: unknown;
2881
2992
  } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2882
2993
  Insert: unknown;
2883
- } ? Relation$1['Insert'] : never, Row>, options?: {
2884
- count?: 'exact' | 'planned' | 'estimated' | (string & {});
2885
- }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
2886
- insert<Row extends (Relation$1 extends {
2994
+ } ? Relation$1['Insert'] : never, Row> | RejectExcessProperties<Relation$1 extends {
2887
2995
  Insert: unknown;
2888
- } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2889
- Insert: unknown;
2890
- } ? Relation$1['Insert'] : never, Row>[], options?: {
2996
+ } ? Relation$1['Insert'] : never, Row>[], {
2997
+ count,
2998
+ defaultToNull
2999
+ }?: {
2891
3000
  count?: 'exact' | 'planned' | 'estimated' | (string & {});
2892
3001
  defaultToNull?: boolean;
2893
3002
  }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
3003
+ /**
3004
+ * Perform an UPSERT on the table or view. Depending on the column(s) passed
3005
+ * to `onConflict`, `.upsert()` allows you to perform the equivalent of
3006
+ * `.insert()` if a row with the corresponding `onConflict` columns doesn't
3007
+ * exist, or if it does exist, perform an alternative action depending on
3008
+ * `ignoreDuplicates`.
3009
+ *
3010
+ * By default, upserted rows are not returned. To return it, chain the call
3011
+ * with `.select()`.
3012
+ *
3013
+ * @param values - The values to upsert with. Pass an object to upsert a
3014
+ * single row or an array to upsert multiple rows.
3015
+ *
3016
+ * @param options - Named parameters
3017
+ *
3018
+ * @param options.onConflict - Comma-separated UNIQUE column(s) to specify how
3019
+ * duplicate rows are determined. Two rows are duplicates if all the
3020
+ * `onConflict` columns are equal.
3021
+ *
3022
+ * @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If
3023
+ * `false`, duplicate rows are merged with existing rows.
3024
+ *
3025
+ * @param options.count - Count algorithm to use to count upserted rows.
3026
+ *
3027
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
3028
+ * hood.
3029
+ *
3030
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
3031
+ * statistics under the hood.
3032
+ *
3033
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
3034
+ * numbers.
3035
+ *
3036
+ * @param options.defaultToNull - Make missing fields default to `null`.
3037
+ * Otherwise, use the default value for the column. This only applies when
3038
+ * inserting new rows, not when merging with existing rows under
3039
+ * `ignoreDuplicates: false`. This also only applies when doing bulk upserts.
3040
+ *
3041
+ * @example Upsert a single row using a unique key
3042
+ * ```ts
3043
+ * // Upserting a single row, overwriting based on the 'username' unique column
3044
+ * const { data, error } = await supabase
3045
+ * .from('users')
3046
+ * .upsert({ username: 'supabot' }, { onConflict: 'username' })
3047
+ *
3048
+ * // Example response:
3049
+ * // {
3050
+ * // data: [
3051
+ * // { id: 4, message: 'bar', username: 'supabot' }
3052
+ * // ],
3053
+ * // error: null
3054
+ * // }
3055
+ * ```
3056
+ *
3057
+ * @example Upsert with conflict resolution and exact row counting
3058
+ * ```ts
3059
+ * // Upserting and returning exact count
3060
+ * const { data, error, count } = await supabase
3061
+ * .from('users')
3062
+ * .upsert(
3063
+ * {
3064
+ * id: 3,
3065
+ * message: 'foo',
3066
+ * username: 'supabot'
3067
+ * },
3068
+ * {
3069
+ * onConflict: 'username',
3070
+ * count: 'exact'
3071
+ * }
3072
+ * )
3073
+ *
3074
+ * // Example response:
3075
+ * // {
3076
+ * // data: [
3077
+ * // {
3078
+ * // id: 42,
3079
+ * // handle: "saoirse",
3080
+ * // display_name: "Saoirse"
3081
+ * // }
3082
+ * // ],
3083
+ * // count: 1,
3084
+ * // error: null
3085
+ * // }
3086
+ * ```
3087
+ *
3088
+ * @category Database
3089
+ *
3090
+ * @remarks
3091
+ * - Primary keys must be included in `values` to use upsert.
3092
+ *
3093
+ * @example Upsert your data
3094
+ * ```ts
3095
+ * const { data, error } = await supabase
3096
+ * .from('instruments')
3097
+ * .upsert({ id: 1, name: 'piano' })
3098
+ * .select()
3099
+ * ```
3100
+ *
3101
+ * @exampleSql Upsert your data
3102
+ * ```sql
3103
+ * create table
3104
+ * instruments (id int8 primary key, name text);
3105
+ *
3106
+ * insert into
3107
+ * instruments (id, name)
3108
+ * values
3109
+ * (1, 'harpsichord');
3110
+ * ```
3111
+ *
3112
+ * @exampleResponse Upsert your data
3113
+ * ```json
3114
+ * {
3115
+ * "data": [
3116
+ * {
3117
+ * "id": 1,
3118
+ * "name": "piano"
3119
+ * }
3120
+ * ],
3121
+ * "status": 201,
3122
+ * "statusText": "Created"
3123
+ * }
3124
+ * ```
3125
+ *
3126
+ * @example Bulk Upsert your data
3127
+ * ```ts
3128
+ * const { data, error } = await supabase
3129
+ * .from('instruments')
3130
+ * .upsert([
3131
+ * { id: 1, name: 'piano' },
3132
+ * { id: 2, name: 'harp' },
3133
+ * ])
3134
+ * .select()
3135
+ * ```
3136
+ *
3137
+ * @exampleSql Bulk Upsert your data
3138
+ * ```sql
3139
+ * create table
3140
+ * instruments (id int8 primary key, name text);
3141
+ *
3142
+ * insert into
3143
+ * instruments (id, name)
3144
+ * values
3145
+ * (1, 'harpsichord');
3146
+ * ```
3147
+ *
3148
+ * @exampleResponse Bulk Upsert your data
3149
+ * ```json
3150
+ * {
3151
+ * "data": [
3152
+ * {
3153
+ * "id": 1,
3154
+ * "name": "piano"
3155
+ * },
3156
+ * {
3157
+ * "id": 2,
3158
+ * "name": "harp"
3159
+ * }
3160
+ * ],
3161
+ * "status": 201,
3162
+ * "statusText": "Created"
3163
+ * }
3164
+ * ```
3165
+ *
3166
+ * @exampleDescription Upserting into tables with constraints
3167
+ * In the following query, `upsert()` implicitly uses the `id`
3168
+ * (primary key) column to determine conflicts. If there is no existing
3169
+ * row with the same `id`, `upsert()` inserts a new row, which
3170
+ * will fail in this case as there is already a row with `handle` `"saoirse"`.
3171
+ * Using the `onConflict` option, you can instruct `upsert()` to use
3172
+ * another column with a unique constraint to determine conflicts.
3173
+ *
3174
+ * @example Upserting into tables with constraints
3175
+ * ```ts
3176
+ * const { data, error } = await supabase
3177
+ * .from('users')
3178
+ * .upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' })
3179
+ * .select()
3180
+ * ```
3181
+ *
3182
+ * @exampleSql Upserting into tables with constraints
3183
+ * ```sql
3184
+ * create table
3185
+ * users (
3186
+ * id int8 generated by default as identity primary key,
3187
+ * handle text not null unique,
3188
+ * display_name text
3189
+ * );
3190
+ *
3191
+ * insert into
3192
+ * users (id, handle, display_name)
3193
+ * values
3194
+ * (1, 'saoirse', null);
3195
+ * ```
3196
+ *
3197
+ * @exampleResponse Upserting into tables with constraints
3198
+ * ```json
3199
+ * {
3200
+ * "error": {
3201
+ * "code": "23505",
3202
+ * "details": "Key (handle)=(saoirse) already exists.",
3203
+ * "hint": null,
3204
+ * "message": "duplicate key value violates unique constraint \"users_handle_key\""
3205
+ * },
3206
+ * "status": 409,
3207
+ * "statusText": "Conflict"
3208
+ * }
3209
+ * ```
3210
+ */
2894
3211
  upsert<Row extends (Relation$1 extends {
2895
3212
  Insert: unknown;
2896
3213
  } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2897
3214
  Insert: unknown;
2898
- } ? Relation$1['Insert'] : never, Row>, options?: {
2899
- onConflict?: string;
2900
- ignoreDuplicates?: boolean;
2901
- count?: 'exact' | 'planned' | 'estimated' | (string & {});
2902
- }): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1['Row'], null, RelationName, Relationships, 'POST'>;
2903
- upsert<Row extends (Relation$1 extends {
3215
+ } ? Relation$1['Insert'] : never, Row> | RejectExcessProperties<Relation$1 extends {
2904
3216
  Insert: unknown;
2905
- } ? Relation$1['Insert'] : never)>(values: RejectExcessProperties<Relation$1 extends {
2906
- Insert: unknown;
2907
- } ? Relation$1['Insert'] : never, Row>[], options?: {
3217
+ } ? Relation$1['Insert'] : never, Row>[], {
3218
+ onConflict,
3219
+ ignoreDuplicates,
3220
+ count,
3221
+ defaultToNull
3222
+ }?: {
2908
3223
  onConflict?: string;
2909
3224
  ignoreDuplicates?: boolean;
2910
3225
  count?: 'exact' | 'planned' | 'estimated' | (string & {});