1
- ## admin-bro -typeorm
1
+ ## adminjs -typeorm
2
2
3
- This is an official [ admin-bro ] ( https://github.com/SoftwareBrothers/admin-bro ) adapter which integrates [ TypeORM] ( https://typeorm.io/ ) into admin-bro . (originally forked from [ Arteha/admin-bro-typeorm] ( https://github.com/Arteha/admin-bro-typeorm ) )
3
+ This is an official [ AdminJS ] ( https://github.com/SoftwareBrothers/adminjs ) adapter which integrates [ TypeORM] ( https://typeorm.io/ ) into AdminJS . (originally forked from [ Arteha/admin-bro-typeorm] ( https://github.com/Arteha/admin-bro-typeorm ) )
4
4
5
- Installation: ` yarn add @admin-bro /typeorm `
5
+ Installation: ` yarn add @adminjs /typeorm `
6
6
7
7
## Usage
8
8
9
- The plugin can be registered using standard ` AdminBro .registerAdapter` method.
10
- o
9
+ The plugin can be registered using standard ` AdminJS .registerAdapter` method.
10
+
11
11
``` typescript
12
- import { Database , Resource } from ' @admin-bro /typeorm'
13
- import AdminBro from ' admin-bro '
12
+ import { Database , Resource } from ' @adminjs /typeorm'
13
+ import AdminJS from ' adminjs '
14
14
15
- AdminBro .registerAdapter ({ Database , Resource });
15
+ AdminJS .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'
@@ -23,67 +23,67 @@ Resource.validate = validate
23
23
24
24
``` typescript
25
25
import {
26
- BaseEntity ,
27
- Entity , PrimaryGeneratedColumn , Column ,
28
- createConnection ,
29
- ManyToOne ,
30
- RelationId
26
+ BaseEntity ,
27
+ Entity , PrimaryGeneratedColumn , Column ,
28
+ createConnection ,
29
+ ManyToOne ,
30
+ RelationId
31
31
} from ' typeorm'
32
32
import * as express from ' express'
33
- import { Database , Resource } from ' @admin-bro /typeorm'
33
+ import { Database , Resource } from ' @adminjs /typeorm'
34
34
import { validate } from ' class-validator'
35
35
36
- import AdminBro from ' admin-bro '
37
- import * as AdminBroExpress from ' @admin-bro /express'
36
+ import AdminJS from ' adminjs '
37
+ import * as AdminJSExpress from ' @adminjs /express'
38
38
39
39
Resource .validate = validate
40
- AdminBro .registerAdapter ({ Database , Resource })
40
+ AdminJS .registerAdapter ({ Database , Resource })
41
41
42
42
@Entity ()
43
43
export class Person extends BaseEntity
44
44
{
45
- @PrimaryGeneratedColumn ()
46
- public id: number ;
47
-
48
- @Column ({type: ' varchar' })
49
- public firstName: string ;
50
-
51
- @Column ({type: ' varchar' })
52
- public lastName: string ;
53
-
54
- @ManyToOne (type => CarDealer , carDealer => carDealer .cars )
55
- organization: Organization ;
56
-
57
- // in order be able to fetch resources in admin-bro - we have to have id available
58
- @RelationId ((person : Person ) => person .organization )
59
- organizationId: number ;
60
-
61
- // For fancy clickable relation links:
62
- public toString(): string
63
- {
64
- return ` ${firstName } ${lastName } ` ;
65
- }
45
+ @PrimaryGeneratedColumn ()
46
+ public id: number ;
47
+
48
+ @Column ({type: ' varchar' })
49
+ public firstName: string ;
50
+
51
+ @Column ({type: ' varchar' })
52
+ public lastName: string ;
53
+
54
+ @ManyToOne (type => CarDealer , carDealer => carDealer .cars )
55
+ organization: Organization ;
56
+
57
+ // in order be able to fetch resources in adminjs - we have to have id available
58
+ @RelationId ((person : Person ) => person .organization )
59
+ organizationId: number ;
60
+
61
+ // For fancy clickable relation links:
62
+ public toString(): string
63
+ {
64
+ return ` ${firstName } ${lastName } ` ;
65
+ }
66
66
}
67
67
68
68
( async () =>
69
69
{
70
- const connection = await createConnection ({/* ... */ })
71
-
72
- // Applying connection to model
73
- Person .useConnection (connection )
74
-
75
- const adminBro = new AdminBro ({
76
- // databases: [connection],
77
- resources: [
78
- { resource: Person , options: { parent: { name: ' foobar' } } }
79
- ],
80
- rootPath: ' /admin' ,
81
- })
82
-
83
- const app = express ()
84
- const router = AdminBroExpress .buildRouter (adminBro )
85
- app .use (adminBro .options .rootPath , router )
86
- app .listen (3000 )
70
+ const connection = await createConnection ({/* ... */ })
71
+
72
+ // Applying connection to model
73
+ Person .useConnection (connection )
74
+
75
+ const adminJs = new AdminJS ({
76
+ // databases: [connection],
77
+ resources: [
78
+ { resource: Person , options: { parent: { name: ' foobar' } } }
79
+ ],
80
+ rootPath: ' /admin' ,
81
+ })
82
+
83
+ const app = express ()
84
+ const router = AdminJSExpress .buildRouter (adminJs )
85
+ app .use (adminJs .options .rootPath , router )
86
+ app .listen (3000 )
87
87
})()
88
88
```
89
89
@@ -112,15 +112,15 @@ yarn link
112
112
113
113
4 . Setup example app
114
114
115
- Install all dependencies and use previously linked version of ` @admin-bro /typeorm ` .
115
+ Install all dependencies and use previously linked version of ` @adminjs /typeorm ` .
116
116
117
117
```
118
118
cd example-app
119
119
yarn install
120
- yarn link @admin-bro /typeorm
120
+ yarn link @adminjs /typeorm
121
121
```
122
122
123
- Optionally you might want to link your local version of ` admin-bro ` package
123
+ Optionally you might want to link your local version of ` adminjs ` package
124
124
125
125
5 . Make sure you have all the envs set (which are defined in ` example-app/ormconfig.js ` )
126
126
0 commit comments