You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/typescript-sdk/introduction.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ const db = new RushDB("RUSHDB_API_KEY");
57
57
58
58
// Push any data, and RushDB will automatically flatten it into Records
59
59
// and establish relationships between them accordingly.
60
-
awaitdb.records.createMany({
60
+
awaitdb.records.importJson({
61
61
label: "COMPANY",
62
62
data: {
63
63
name: 'Google LLC',
@@ -164,7 +164,7 @@ const db = new RushDB('RUSHDB_API_KEY', {
164
164
165
165
## SDK Architecture
166
166
167
-
The RushDB SDK uses a consistent approach for accessing the RushDB API instance across all SDK components. Classes like `Transaction`, `DBRecordInstance`, `DBRecordsArrayInstance` and `Model` all use the static `RushDB.init()` method to obtain the API instance, ensuring a uniform pattern throughout the SDK.
167
+
The RushDB SDK uses a consistent approach for accessing the RushDB API instance across all SDK components. Classes like `Transaction`, `DBRecordInstance`, `DBRecordsArrayInstance` and `Model` all use the static `RushDB.getInstance()` method to obtain the API instance, ensuring a uniform pattern throughout the SDK.
168
168
169
169
This architecture provides several benefits:
170
170
@@ -177,7 +177,7 @@ Example of the implementation pattern:
Copy file name to clipboardExpand all lines: docs/docs/typescript-sdk/models.md
+6-87Lines changed: 6 additions & 87 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,23 +149,15 @@ export type UserSearchQuery = SearchQuery<typeof UserModel.schema>;
149
149
150
150
### Model Implementation Architecture
151
151
152
-
The `Model` class uses the same architectural pattern as other SDK components like `Transaction` and `DBRecordInstance`. It uses the static `RushDB.init()` method to access the API:
152
+
The `Model` class uses the same architectural pattern as other SDK components like `Transaction` and `DBRecordInstance`. It uses the static `RushDB.getInstance()` method to access the API:
throw new Error('No RushDB instance found. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')
168
-
}
169
161
```
170
162
171
163
This architecture ensures consistent API access across all SDK components.
@@ -248,8 +240,8 @@ import RushDB from '@rushdb/javascript-sdk';
248
240
exportconst db =newRushDB('RUSHDB_API_KEY');
249
241
250
242
// You can also export a helper function to access the instance
251
-
exportconst getRushDBInstance =async() => {
252
-
returnawaitRushDB.init();
243
+
exportconst getRushDBInstance = () => {
244
+
returnRushDB.getInstance();
253
245
};
254
246
```
255
247
@@ -351,82 +343,9 @@ await AuthorModel.detach({
351
343
352
344
## Advanced TypeScript Support
353
345
354
-
When working with RushDB SDK, achieving perfect TypeScript contracts ensures a seamless development experience. TypeScript's strong typing system allows for precise autocomplete suggestions and error checking, particularly when dealing with complex queries and nested models. This section will guide you on how to enhance TypeScript support by defining comprehensive type definitions for your models.
355
-
356
-
### Defining Comprehensive TypeScript Types
357
-
358
-
To fully leverage TypeScript's capabilities, you can define types that include all schemas you've registered with `Model`. This will allow you to perform complex queries with nested model fields, ensuring type safety and better autocompletion.
#### Step 2: Create an Exportable Type for All Schemas
386
-
387
-
Next, create an exportable type that includes all the schemas defined in your application:
388
-
```typescript
389
-
exporttypeMyModels= {
390
-
author:typeofAuthorModel.schema
391
-
post:typeofPostModel.schema
392
-
blog:typeofBlogModel.schema
393
-
}
394
-
```
395
-
396
-
#### Step 3: Extend the Models Interface
397
-
398
-
Add this type declaration to your project. This ensures that RushDB SDK is aware of your models:
399
-
```typescript
400
-
// index.d.ts or other d.ts file added to include in tsconfig.json
401
-
402
-
import { MyModels } from'./types';
403
-
404
-
declaremodule'@rushdb/javascript-sdk' {
405
-
exportinterfaceModelsextendsMyModels {}
406
-
}
407
-
```
408
-
409
-
### Example Usage: Complex Queries with Type Safety
410
-
411
-
By following these steps, you can now write complex queries with confidence, knowing that TypeScript will help you avoid errors and provide accurate autocomplete suggestions. Here's an example demonstrating how you can leverage this setup:
412
-
413
-
```typescript
414
-
const query =awaitdb.records.find({
415
-
labels: ['post'],
416
-
where: {
417
-
author: {
418
-
name: { $contains: 'John' }, // Checking if the author's name contains 'John'
419
-
post: {
420
-
rating: { $gt: 5 } // Posts with rating greater than 5
421
-
}
422
-
}
423
-
}
424
-
});
425
-
```
426
-
427
-
In this example, the `db.records.find` method allows you to use nested fields in the `where` condition, thanks to the enhanced TypeScript definitions. This ensures that you can easily and accurately query your data, leveraging the full power of TypeScript.
346
+
For a complete, up-to-date guide on configuring declaration merging, path aliases, and schema-aware intellisense (including typed related queries), see the Model reference: [TypeScript: extend SDK types for schema-aware suggestions](./typescript-reference/Model#typescript-extend-sdk-types-for-schema-aware-suggestions).
428
347
429
-
By defining comprehensive type definitions for your models and extending the `Models` interface, you can significantly enhance your TypeScript support when working with RushDB SDK. This approach ensures type safety, better autocompletion, and a more efficient development experience.
348
+
Note on result typing with aggregations/grouping: when you use `aggregate` or `groupBy`, the result shape can differ from your schema. You can augment the instance type as `typeof Model.recordInstance & { data: T }` to describe the returned payload. See the dedicated explanation and examples in the Model reference, and the concepts for [Aggregations](../concepts/search/aggregations) and [Grouping](../concepts/search/group-by).
Copy file name to clipboardExpand all lines: docs/docs/typescript-sdk/records/create-records.md
+47-3Lines changed: 47 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,9 +165,9 @@ Each property draft object supports the following properties:
165
165
166
166
## Creating Multiple Records
167
167
168
-
When you need to create multiple records in a single operation, use the `records.createMany` method.
168
+
When you need to create multiple flat records (CSV-like rows) in a single operation, use the `records.createMany` method. For nested or complex JSON, use `records.importJson`.
169
169
170
-
### Using RushDB's `createMany()` Method
170
+
### Using RushDB's `createMany()` Method (flat rows only)
171
171
172
172
```typescript
173
173
const authors =awaitdb.records.createMany({
@@ -206,14 +206,58 @@ console.log(authors);
206
206
#### Parameters
207
207
208
208
-`label`: The [label](../../concepts/labels.md)/type for all records
209
-
-`data`: Object (nested too) or an array of objects, each representing a record to create
209
+
-`data`: An object or array of objects, each a flat record (no nested objects/arrays)
210
210
-`options` (optional): Configuration options for record creation:
211
211
-`suggestTypes` (boolean, default: `true`): When true, automatically infers data types for [properties](../../concepts/properties.md)
212
212
-`castNumberArraysToVectors` (boolean, default: `false`): When true, converts numeric arrays to vector type
213
213
-`convertNumericValuesToNumbers` (boolean, default: `false`): When true, converts string numbers to number type
214
214
-`capitalizeLabels` (bool): When true, converts all labels to uppercase
215
215
-`relationshipType` (str): Default relationship type between nodes
216
216
-`returnResult` (bool, default: `false`): When true, returns imported records in response
217
+
- Throws if any record contains nested objects/arrays. Use `records.importJson` for that.
218
+
219
+
### Using RushDB's `importJson()` Method (nested JSON)
220
+
221
+
Use `importJson` for nested objects, arrays of nested objects, or hash-map like payloads.
0 commit comments