@@ -7,16 +7,16 @@ Installation: `yarn add @admin-bro/typeorm`
7
7
## Usage
8
8
9
9
The plugin can be registered using standard ` AdminBro.registerAdapter ` method.
10
-
10
+ o
11
11
``` typescript
12
- import { Database , Resource } from " @admin-bro/typeorm" ;
12
+ import { Database , Resource } from ' @admin-bro/typeorm'
13
13
import AdminBro from ' admin-bro'
14
14
15
15
AdminBro .registerAdapter ({ Database , Resource });
16
16
17
17
// optional: if you use class-validator you have to inject this to resource.
18
18
import { validate } from ' class-validator'
19
- Resource .validate = validate ;
19
+ Resource .validate = validate
20
20
```
21
21
22
22
## Example
@@ -28,16 +28,16 @@ import {
28
28
createConnection ,
29
29
ManyToOne ,
30
30
RelationId
31
- } from ' typeorm' ;
32
- import * as express from ' express' ;
33
- import { Database , Resource } from ' @admin-bro/typeorm' ;
31
+ } from ' typeorm'
32
+ import * as express from ' express'
33
+ import { Database , Resource } from ' @admin-bro/typeorm'
34
34
import { validate } from ' class-validator'
35
35
36
- import AdminBro from ' admin-bro' ;
36
+ import AdminBro from ' admin-bro'
37
37
import * as AdminBroExpress from ' @admin-bro/express'
38
38
39
- Resource .validate = validate ;
40
- AdminBro .registerAdapter ({ Database , Resource });
39
+ Resource .validate = validate
40
+ AdminBro .registerAdapter ({ Database , Resource })
41
41
42
42
@Entity ()
43
43
export class Person extends BaseEntity
@@ -67,26 +67,86 @@ export class Person extends BaseEntity
67
67
68
68
( async () =>
69
69
{
70
- const connection = await createConnection ({/* ... */ });
70
+ const connection = await createConnection ({/* ... */ })
71
71
72
72
// Applying connection to model
73
- Person .useConnection (connection );
73
+ Person .useConnection (connection )
74
74
75
75
const adminBro = new AdminBro ({
76
76
// databases: [connection],
77
77
resources: [
78
78
{ resource: Person , options: { parent: { name: ' foobar' } } }
79
79
],
80
80
rootPath: ' /admin' ,
81
- });
81
+ })
82
82
83
- const app = express ();
84
- const router = AdminBroExpress .buildRouter (adminBro );
85
- app .use (adminBro .options .rootPath , router );
86
- app .listen (3000 );
87
- })();
83
+ const app = express ()
84
+ const router = AdminBroExpress .buildRouter (adminBro )
85
+ app .use (adminBro .options .rootPath , router )
86
+ app .listen (3000 )
87
+ })()
88
88
```
89
89
90
90
## ManyToOne
91
91
92
92
Admin supports ManyToOne relationship but you also have to define @RealationId as stated in the example above.
93
+
94
+ ## Contribution
95
+
96
+ ### Running the example app
97
+
98
+ If you want to set this up locally this is the suggested process:
99
+
100
+ 1 . fork the repo
101
+ 2 . Install dependencies
102
+
103
+ ```
104
+ yarn install
105
+ ```
106
+
107
+ 3 . register this package as a (linked package)[ https://classic.yarnpkg.com/en/docs/cli/link/ ]
108
+
109
+ ```
110
+ yarn link
111
+ ```
112
+
113
+ 4 . Setup example app
114
+
115
+ Install all dependencies and use previously linked version of ` @admin-bro/typeorm ` .
116
+
117
+ ```
118
+ cd example-app
119
+ yarn install
120
+ yarn link @admin-bro/typeorm
121
+ ```
122
+
123
+ Optionally you might want to link your local version of ` admin-bro ` package
124
+
125
+ 5 . Make sure you have all the envs set (which are defined in ` example-app/ormconfig.js ` )
126
+
127
+ 6 . Build the package in watch mode
128
+
129
+ (in the root folder)
130
+
131
+ ```
132
+ yarn watch
133
+ ```
134
+
135
+ 6 . run the app in the dev mode
136
+
137
+ ```
138
+ cd example-app
139
+ yarn start:dev
140
+ ```
141
+
142
+ ### Pull request
143
+
144
+ Before you make a PR make sure all tests pass and your code wont causes linter errors.
145
+ You can do this by running:
146
+
147
+ ```
148
+ yarn lint
149
+ yarn test
150
+ ```
151
+
152
+ or with proper envs: ` POSTGRES_USER=yourtestuser POSTGRES_DATABASE="database_test" yarn test `
0 commit comments