Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: developer concepts 2 #47

Closed
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions guides/developers-guide/concepts/simple-schemas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Schemas
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not a duplicate?


Open Commerce uses [MongoDB](https://docs.mongodb.com/manual/), which is a schemaless database. This allows maximum flexibility, particularly important when quickly reacting to the design challenges that uniquely different customizations require in the course of an e-commerce operation.

However, we don't want to just get completely crazy, so we define a **schema** that is attached to the previously schemaless collection. These schemas apply basic content and structure validation, also very necessary in e-commerce.

Schemas are implemented using the [simpl-schema](https://github.com/aldeed/simple-schema-js) NPM package. In most cases the schemas can be kept private to the plugin that creates them. Typically, you will import them into a mutation function and validate a document before inserting or updating it.

```js
OrderSchema.validate(order); // Will throw a validation error if invalid
await Orders.insertOne(order);
```

An update example:

```js
OrderSchema.validate(modifier, { modifier: true });

const { value: updatedOrder } = await Orders.findOneAndUpdate(
{ _id: orderId },
modifier,
{ returnOriginal: false }
);
```
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file added how-tos/add-translations.md
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added how-tos/create-a-tax-plugin.md
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/postlight/mailchimp-open-commerce-docs.git"
"url": "git+https://github.com/reactioncommerce/docs.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/postlight/mailchimp-open-commerce-docs/issues"
"url": "https://github.com/reactioncommerce/docs/issues"
},
"homepage": "https://github.com/postlight/mailchimp-open-commerce-docs#readme",
"homepage": "https://github.com/reactioncommerce/docs#readme",
"devDependencies": {}
}