@m1212e/rumble 0.13.3 → 0.14.2
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/README.md +64 -1
- package/out/index.cjs +9 -8
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +10 -6
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +10 -6
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +9 -8
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -210,6 +210,69 @@ const enumRef = enum_({
|
|
|
210
210
|
```
|
|
211
211
|
> The enum parameter allows other fields to be used to reference an enum. This is largely due to how this is used internally. Because of the way how drizzle handles enums, we are not able to provide type safety with enums. In case you actually need to use it, the above way is the recommended approach.
|
|
212
212
|
|
|
213
|
+
### Enable search
|
|
214
|
+
> Search is currently only supported in postgres!
|
|
215
|
+
|
|
216
|
+
rumble and its helpers offer out of the box search capabilities. You can activate this functionality by passing the `search` parameter to the `createRumble` function.
|
|
217
|
+
```ts
|
|
218
|
+
const rumble = createRumble({
|
|
219
|
+
...
|
|
220
|
+
search: {
|
|
221
|
+
enabled: true,
|
|
222
|
+
threshold: 0.2, // optionally adjust this value to your needs
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
This will add a search field to all list queries and many relations created by the rumble helper functions. E.g. if you have a `users` table with a `name` and `email` field, and use the `object` and `query` helpers to implement queries for this table, you will get a search argument like this:
|
|
227
|
+
```graphql
|
|
228
|
+
{
|
|
229
|
+
users(limit: 10, search: "alice") {
|
|
230
|
+
id
|
|
231
|
+
name
|
|
232
|
+
email
|
|
233
|
+
search_distance
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
Additionally, a search distance will be returned for each result if the search argument is used (null otherwise). The results are returned sorted by their distance with the best matching fields in the first place. The search will respect all text fields (IDs included) on the table, you always search for all text columns at once. Matches in multiple columns stack and therefore result in a better matching score. So if you search for "alice" and there is a user with the name "Alice" and an email "alice@example.com", the two matching columns will result in a better score than e.g. "al007@example.com"/"Alice".
|
|
238
|
+
> If you have abilities in place which prevent a caller from accessing certain columns, the search will not respect those columns to prevent leaking information.
|
|
239
|
+
#### Pro tip: Indexing
|
|
240
|
+
In case your table grows large, it can be a good idea to create an index to increase performance. Under the hood, searching uses the [pg_trgm](https://www.postgresql.org/docs/current/pgtrgm.html#PGTRGM-INDEX) extension. To create indexes for our searchable columns, we can adjust our drizzle schema accordingly:
|
|
241
|
+
```ts
|
|
242
|
+
export const user = pgTable('user', {
|
|
243
|
+
id: text()
|
|
244
|
+
.$defaultFn(() => nanoid())
|
|
245
|
+
.primaryKey(),
|
|
246
|
+
email: text().notNull().unique(),
|
|
247
|
+
name: text().notNull(),
|
|
248
|
+
},
|
|
249
|
+
(table) => [
|
|
250
|
+
index('user_id_trgm')
|
|
251
|
+
.using('gin', sql`${table.id} gin_trgm_ops`)
|
|
252
|
+
.concurrently(),
|
|
253
|
+
index('user_email_trgm')
|
|
254
|
+
.using('gin', sql`${table.email} gin_trgm_ops`)
|
|
255
|
+
.concurrently(),
|
|
256
|
+
index('user_name_trgm')
|
|
257
|
+
.using('gin', sql`${table.name} gin_trgm_ops`)
|
|
258
|
+
.concurrently(),
|
|
259
|
+
],
|
|
260
|
+
);
|
|
261
|
+
```
|
|
262
|
+
> When deciding to create indexes for faster searches, ensure that you create them for all text based columns that exist in your table. This includes `text`, `char`, `varchar` and so on. Since rumble always searches all the text columns, it is recommended to create indexes for all text columns in your table, otherwise the search might not be as fast as possible.
|
|
263
|
+
|
|
264
|
+
In case you never started rumble with the search mode activated and you want to create the indexes in your migration, please ensure that the `pg_trgm` extension is installed and enabled in your database. You can do this by running the following SQL command:
|
|
265
|
+
```sql
|
|
266
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
267
|
+
```
|
|
268
|
+
rumble does this automatically on startup if the search feature is enabled, nonetheless it is recommended to include the extension installation in your migration scripts to ensure that the extension is available when you create the indexes which rely on it.
|
|
269
|
+
|
|
270
|
+
**What this means for you**: After creating the migration files containing the indexes the first time with the `drizzle-kit generate` command (or your respective migration tool), add the above SQL statement before any index creation inside that generated migration file. This will ensure that the extension is installed and enabled before the indexes that rely on it are created.
|
|
271
|
+
|
|
272
|
+
Another important aspect to consider when using indexes is that the PostgreSQL instance should be properly configured for optimal performance (e.g. the drive type you use might have an impact). This includes tuning settings such as `random_page_cost` and `effective_io_concurrency`. Please see [this quick writeup on the topic](https://blog.frehi.be/2025/07/28/tuning-postgresql-performance-for-ssd). If not done properly, your indexes might not be used as expected rendering them useless.
|
|
273
|
+
|
|
274
|
+
Please also note that `GIST` indexes are also supported by `pg_trgm` but will oftentimes not be useable for the sorting since a lot of columns are accumulated in the query which causes the query planner to not use them. Feel free to experiment with different index types and configurations to find the best fit for your specific use case.
|
|
275
|
+
|
|
213
276
|
### and more...
|
|
214
277
|
See [the example file](./example/src/main.ts) or clone it and let intellisense guide you. Rumble offers various other helpers which might become handy!
|
|
215
278
|
|
|
@@ -288,4 +351,4 @@ await generateFromSchema({
|
|
|
288
351
|
outputPath: "./generated";
|
|
289
352
|
})
|
|
290
353
|
```
|
|
291
|
-
This might become handy in separate code bases for api and client.
|
|
354
|
+
This might become handy in separate code bases for api and client.
|
package/out/index.cjs
CHANGED
|
@@ -247,7 +247,7 @@ export const schema = ${(0, devalue.uneval)((0, __urql_introspection.minifyIntro
|
|
|
247
247
|
//#endregion
|
|
248
248
|
//#region lib/client/request.ts
|
|
249
249
|
const argsKey = "__args";
|
|
250
|
-
function
|
|
250
|
+
function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false }) {
|
|
251
251
|
const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
|
|
252
252
|
const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
|
|
253
253
|
const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
|
|
@@ -271,7 +271,7 @@ function makeGraphQLQuery({ queryName, input, client, enableSubscription = false
|
|
|
271
271
|
Object.assign(promise, observable);
|
|
272
272
|
return promise;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function makeGraphQLMutationRequest({ mutationName, input, client }) {
|
|
275
275
|
const otwMutationName = `${(0, es_toolkit.capitalize)(mutationName)}Mutation`;
|
|
276
276
|
const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
|
|
277
277
|
const response = (0, wonka.pipe)(client.mutation(`mutation ${otwMutationName} { ${mutationName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
|
|
@@ -284,7 +284,7 @@ function makeGraphQLMutation({ mutationName, input, client }) {
|
|
|
284
284
|
Object.assign(promise, observable);
|
|
285
285
|
return promise;
|
|
286
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function makeGraphQLSubscriptionRequest({ subscriptionName, input, client }) {
|
|
288
288
|
const otwSubscriptionName = `${(0, es_toolkit.capitalize)(subscriptionName)}Subscription`;
|
|
289
289
|
const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
|
|
290
290
|
return (0, wonka.pipe)(client.subscription(`subscription ${otwSubscriptionName} { ${subscriptionName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
|
|
@@ -333,7 +333,7 @@ function stringifyArgumentValue(arg) {
|
|
|
333
333
|
function makeLiveQuery({ urqlClient, availableSubscriptions }) {
|
|
334
334
|
return new Proxy({}, { get: (_target, prop) => {
|
|
335
335
|
return (input) => {
|
|
336
|
-
return
|
|
336
|
+
return makeGraphQLQueryRequest({
|
|
337
337
|
queryName: prop,
|
|
338
338
|
input,
|
|
339
339
|
client: urqlClient,
|
|
@@ -348,7 +348,7 @@ function makeLiveQuery({ urqlClient, availableSubscriptions }) {
|
|
|
348
348
|
function makeMutation({ urqlClient }) {
|
|
349
349
|
return new Proxy({}, { get: (_target, prop) => {
|
|
350
350
|
return (input) => {
|
|
351
|
-
return
|
|
351
|
+
return makeGraphQLMutationRequest({
|
|
352
352
|
mutationName: prop,
|
|
353
353
|
input,
|
|
354
354
|
client: urqlClient
|
|
@@ -429,7 +429,7 @@ const nativeDateExchange = ({ client, forward }) => {
|
|
|
429
429
|
function makeQuery({ urqlClient }) {
|
|
430
430
|
return new Proxy({}, { get: (_target, prop) => {
|
|
431
431
|
return (input) => {
|
|
432
|
-
return
|
|
432
|
+
return makeGraphQLQueryRequest({
|
|
433
433
|
queryName: prop,
|
|
434
434
|
input,
|
|
435
435
|
client: urqlClient,
|
|
@@ -444,7 +444,7 @@ function makeQuery({ urqlClient }) {
|
|
|
444
444
|
function makeSubscription({ urqlClient }) {
|
|
445
445
|
return new Proxy({}, { get: (_target, prop) => {
|
|
446
446
|
return (input) => {
|
|
447
|
-
return
|
|
447
|
+
return makeGraphQLSubscriptionRequest({
|
|
448
448
|
subscriptionName: prop,
|
|
449
449
|
input,
|
|
450
450
|
client: urqlClient
|
|
@@ -1893,7 +1893,8 @@ const createSchemaBuilder = ({ db, disableDefaultObjects, pubsub, pothosConfig }
|
|
|
1893
1893
|
},
|
|
1894
1894
|
smartSubscriptions: { ...(0, __pothos_plugin_smart_subscriptions.subscribeOptionsFromIterator)((name, _context) => {
|
|
1895
1895
|
return pubsub.subscribe(name);
|
|
1896
|
-
}) }
|
|
1896
|
+
}) },
|
|
1897
|
+
defaultFieldNullability: false
|
|
1897
1898
|
});
|
|
1898
1899
|
schemaBuilder.addScalarType("JSON", graphql_scalars.JSONResolver);
|
|
1899
1900
|
schemaBuilder.addScalarType("Date", graphql_scalars.DateResolver);
|