Skip to content

Commit

Permalink
[automated commit] Bump docs to version 1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leorossi authored and github-actions[bot] committed Nov 15, 2023
1 parent 8394304 commit 837a9ad
Show file tree
Hide file tree
Showing 151 changed files with 640 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And finally, all Platformatic components can be deployed on [Platformatic Cloud]

A Platformatic Service is an HTTP server based on [Fastify](https://www.fastify.io/) that allows developers to build robust APIs with Node.js.
With Platformatic Service you can:
- Add custom functionality in a [Fastify plugin](https://www.fastify.io/docs/latest/Plugins/)
- Add custom functionality in a [Fastify plugin](https://fastify.dev/docs/latest/Reference/Plugins)
- Write plugins in JavaScript or [TypeScript](https://www.typescriptlang.org/)
- Optionally user TypeScript to write your application code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,38 @@ an instance of [`@platformatic/sql-mapper`](/reference/sql-mapper/introduction.m
```javascript title="seed.js"
'use strict'

module.exports = async function ({ entities, db, sql }) {
module.exports = async function seed ({ entities, db, sql }) {
await entities.graph.save({ input: { name: 'Hello' } })
await db.query(sql`
INSERT INTO graphs (name) VALUES ('Hello 2');
`)
}
```

For Typescript use the following stub

```typescript title="seed.ts"
/// <reference path="./global.d.ts" />
import { Entities } from '@platformatic/sql-mapper'

const movies: object[] = [
{ title: 'Harry Potter' },
{ title: 'The Matrix' }
]

export async function seed (opts: { entities: Entities }) {
for (const movie of movies) {
await opts.entities.movie.save({ input: movie })
}
}
```

:::info
Platformatic code will look for a `default` or `seed` function name when importing the file. Take a look at the `execute` function [here](https://github.com/platformatic/platformatic/blob/main/packages/db/lib/seed.mjs)
:::



We can then run the seed script with the Platformatic CLI:

```bash
Expand Down
Loading

0 comments on commit 837a9ad

Please sign in to comment.