Skip to content

Commit db54e91

Browse files
committed
initial commit
0 parents  commit db54e91

28 files changed

Lines changed: 6235 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
node_modules
3+
sqlite.db
4+
dist
5+
temp

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Martin Adámek
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# MikroORM: Getting started
2+
3+
Read the full text on https://mikro-orm.io/docs/guide.
4+
5+
## Introduction
6+
7+
MikroORM is a TypeScript ORM for Node.js based on Data Mapper, Unit of Work, and Identity Map patterns. In this guide, you will learn what those words mean, how to set up a simple API project, how to test it, and many more.
8+
9+
[This Getting Started Guide](https://mikro-orm.io/docs/guide) was written as a step-by-step tutorial, accompanied by working StackBlitz examples and a [GitHub repository with the final project](https://github.com/mikro-orm/guide). It will show you how to create a production-ready application from scratch, all the way down to a docker image you can deploy wherever you want.
10+
11+
## The Stack
12+
13+
The goal of this guide is to show off the most important features of MikroORM as well as some of the more niche ones. It will walk you through creating a simple API for a blog, with the following technologies:
14+
15+
- [MikroORM](https://mikro-orm.io) with SQLite driver
16+
- [Fastify](https://www.fastify.io) as the web framework
17+
- [Vitest](https://vitest.dev) for testing
18+
- ECMAScript modules
19+
- JWT authentication
20+
- reflection via [ts-morph](https://ts-morph.com)
21+
22+
## What are we building?
23+
24+
We already mentioned what technologies will be used, and now more about the project. It will be a simple API for a blog, with authentication, publishing, and commenting. For that, we will use four regular entities: `User`, `Article`, `Comment`, and `Tag`. Later on, we will add one more entity, `ArticleListing`, a virtual entity represented by an SQL expression rather than a database table.
25+
26+
And the API routes description:
27+
28+
| Method | URL | Description |
29+
|----------|--------------------------|-----------------------------------|
30+
| `POST` | `/user/sign-up` | Register new user |
31+
| `POST` | `/user/sign-in` | Login existing user |
32+
| `GET` | `/user/profile` | Get your full profile info |
33+
| `PATCH` | `/user/profile` | Modify your profile |
34+
| `POST` | `/article` | Create new article |
35+
| `GET` | `/article` | List existing articles |
36+
| `GET` | `/article/:slug` | Get article detail |
37+
| `PATCH` | `/article/:slug` | Modify existing article |
38+
| `DELETE` | `/article/:slug` | Delete existing article |
39+
| `POST` | `/article/:slug/comment` | Post comment for existing article |
40+
41+
The code will be structured into self-contained modules: `user`, `article`, and `common` (for shared helpers).
42+
43+
The app will be using Node.js 20, TypeScript 5.2, and we will build it using a modern stack with ECMAScript modules enabled.
44+
45+
## What will we cover
46+
47+
Here is (an incomplete) list of features you will try going through this guide.
48+
49+
- creating an app from scratch with TypeScript setup
50+
- folder-based discovery, ts-morph reflection, ES modules
51+
- request context management via middleware/fastify hook
52+
- entity relations, advanced entity definition (e.g. lazy scalar properties)
53+
- advanced type safety (e.g. `OptionalProps`, `Reference` wrapper and `Loaded` type)
54+
- events, including advanced use cases like soft-delete via `onFlush` event
55+
- basic testing via vitest
56+
- custom repositories
57+
- virtual entities
58+
- serialization
59+
- embeddables
60+

0 commit comments

Comments
 (0)