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: docusaurus/docs/advanced/how-ottoman-works.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Using the default `keyGenerator` function that Ottoman provides and assuming you
25
25
26
26
-`User::0477024c`
27
27
28
-
:::tip Notice
28
+
:::tip Notice
29
29
This resulted key is a combination of the prefix as provided by the default `keyGenerator` function (`${metadata.modelName}`) [appended with an ID](/docs/basic/model.html#model-id) (`0477024c`).
30
30
:::
31
31
@@ -61,7 +61,7 @@ Let see how Ottoman handles a new document creation.
61
61
62
62

63
63
64
-
:::tip Notice
64
+
:::tip Notice
65
65
Using Ottoman you only need to think about `id` in order to execute CRUD Operations over documents.
66
66
All the `key` management will be automatically handled by Ottoman.
Copy file name to clipboardExpand all lines: docusaurus/docs/advanced/ottoman-couchbase.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ If you are familiar with Mongoose, an ODM for MongoDB, you will feel pretty comf
21
21
In Ottoman, we have many constructs to help define schema and models at the application level. Let’s go over some of the most important terms you need to know in Ottoman.
22
22
23
23
24
-
:::tip Couchbase document example:
24
+
:::tip Couchbase document example:
25
25
```json
26
26
{
27
27
"id": 10,
@@ -87,7 +87,7 @@ Can use the IDE that is best to your liking and open the created directory `intr
87
87
88
88
We will start working out of the file `./createAirline.js` under the project root and add the following (based on the default configuration):
@@ -156,7 +156,7 @@ When you call the [`model()`](/docs/api/classes/ottoman.html#model) function it
156
156
157
157
Let’s also give the `airlineSchema` a ***phone number*** property. We can add a validation function that will ensure that the value is a valid phone number. Replace the `airlineSchema` section with these three blocks of code:
@@ -183,7 +183,7 @@ Validators registered with Ottoman (as we have done here with the `ottoman.addVa
183
183
184
184
There is however an easier way to validate any document properties value so long as the check you are performing uses a regular expression. The [ValidatorOption](/docs/api/interfaces/validatoroption.html#hierarchy') can take a regexp and message as an argument, so we can reduce our code down to:
@@ -205,7 +205,7 @@ Most of the basic operations are covered in our Ottoman V2 documentation, we wil
205
205
206
206
Considering the code that we already went over above that creates a `schema`, `model`, and `validators`. *Saving* a `model` and *persisting* it to the database is quite easy. Let’s create a new **Airline**`model` using our `Schema` and then *save/persist* it to the database.
207
207
208
-
:::tip Create Document & Save to Couchbase
208
+
:::tip Create Document & Save to Couchbase
209
209
```js
210
210
// Constructing our document
211
211
constcbAirlines=newAirline({
@@ -275,7 +275,7 @@ If we enter an invalid phone number and run node `createAirline.js` this file ag
275
275
ValidationError: Phone Number 321-321-32xx is not valid
276
276
```
277
277
278
-
:::tip Export Schema and Model
278
+
:::tip Export Schema and Model
279
279
280
280
You can define your *connection*, *schema*, and *models* in separate files, export, and use them in other files. Create a new file named `airline-schema-model.js` and move our `schema` and `model` definition to it:
281
281
@@ -300,7 +300,7 @@ exports.Airline = Airline;
300
300
301
301
Now we can create a few new files, `findAirline.js`, `updateAirline.js`, and `removeAirline.js` and populate each file with the following:
@@ -326,7 +326,7 @@ This will help us to separate some of our code so we are not repeating it in eac
326
326
327
327
Let’s try to retrieve the record we saved to the database earlier. The [model class](/docs/api/classes/model.html) exposes several static and instance methods to perform operations on the database. We will now try to find the record that we created previously using the find method and pass the `callsign` as the search term. Let’s create a new file named `findAirline.js` and we can add the following code:
328
328
329
-
:::tip Find Airline Document by `callsign`
329
+
:::tip Find Airline Document by `callsign`
330
330
```js
331
331
// Find the Couchbase Airline document by Callsign from Couchbase Server
332
332
constfindDocument=async () => {
@@ -367,7 +367,7 @@ Find document result:
367
367
368
368
Let’s modify the record above by finding it using the `callsign`, which we can assume that `callsign` will be a unique field in our data, then we can update the `document` all in a single operation.
369
369
370
-
:::tip Find Airline Document and Update
370
+
:::tip Find Airline Document and Update
371
371
```js
372
372
// Update the Couchbase Airline document by Callsign from Couchbase Server
373
373
constfindDocumentAndUpdate=async () => {
@@ -416,7 +416,7 @@ _Model {
416
416
417
417
Ottoman has several methods that deal with removing documents: [remove](/docs/api/classes/document.html#remove), [removeById](/docs/api/interfaces/imodel.html#removebyid) and [removeMany](/docs/api/interfaces/imodel.html#removemany). Considering the many examples we have had so far, each of these should be very easy to understand how to use, so we will just provide a simple example here to show how to remove a `document` that we have already found using the [find](/docs/api/interfaces/imodel.html#find) method.
418
418
419
-
:::tip Remove Airline Document by ID
419
+
:::tip Remove Airline Document by ID
420
420
```js
421
421
// Remove the Couchbase Airline document by ID from Couchbase Server
422
422
constremoveDocument=async () => {
@@ -452,7 +452,7 @@ Example of Middleware (a.k.a. [pre](/docs/basic/schema.html#register-hooks-with-
452
452
453
453
Let’s try an example by simply generating a log in the console before and after the creation (`save`) of a `document`, We are going to create a new file called `createWithHooks.js` and most of the code will look familiar except we have added `pre` and `post` hooks that will just report to us the document `name`***pre-save*** and document `id`***post-save***:
454
454
455
-
:::tip Create Document with Pre/Post Save Hooks
455
+
:::tip Create Document with Pre/Post Save Hooks
456
456
```js
457
457
const { Ottoman } = require('ottoman')
458
458
const ottoman = new Ottoman({ collectionName: '_default' });
@@ -547,7 +547,7 @@ In the next three examples, we will do the same thing using each of the three di
547
547
548
548
Let’s first create a new file named `findWithQueryBuilder.js`, and add the following code:
549
549
550
-
:::tip Find Airline Document with QueryBuilder
550
+
:::tip Find Airline Document with QueryBuilder
551
551
```js
552
552
const { Ottoman, Query } = require('ottoman')
553
553
const ottoman = new Ottoman({ collectionName: '_default' });
@@ -588,7 +588,7 @@ This file has a comment in the middle that says: ***“Replace with QueryBuilder
0 commit comments