Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-typeorm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
koishi-plugin-typeorm
Commits
1d5006bf
Commit
1d5006bf
authored
Feb 10, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dont use inbuilt connection manager
parent
b879566e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
src/index.ts
src/index.ts
+4
-1
tests/typeorm.spec.ts
tests/typeorm.spec.ts
+8
-3
No files found.
src/index.ts
View file @
1d5006bf
...
...
@@ -73,6 +73,9 @@ export default class TypeORMPlugin extends BasePlugin<TypeORMPluginConfigLike> {
entities
:
TypeORMEntity
[],
extraOptions
:
Partial
<
ConnectionOptions
>
=
{},
)
{
if
(
this
.
registryMap
.
has
(
token
))
{
return
this
.
getConnection
(
token
);
}
const
ctx
=
this
.
caller
;
ctx
.
on
(
'
dispose
'
,
()
=>
this
.
close
(
token
));
...
...
@@ -86,7 +89,7 @@ export default class TypeORMPlugin extends BasePlugin<TypeORMPluginConfigLike> {
name
:
`koishi_
${
token
}
`
,
...
extraOptions
,
};
const
connection
=
await
createConnection
(
connectionOptions
);
const
connection
=
await
new
Connection
(
connectionOptions
).
connect
(
);
this
.
registryMap
.
set
(
token
,
{
connection
,
entities
});
for
(
const
entity
of
entities
)
{
this
.
entityMap
.
set
(
entity
,
token
);
...
...
tests/typeorm.spec.ts
View file @
1d5006bf
...
...
@@ -53,7 +53,7 @@ describe('Koishi typeorm', () => {
port
:
5432
,
username
:
'
koishi
'
,
password
:
'
koishi@114514
'
,
database
:
'
koishi
'
,
database
:
'
test-
koishi
'
,
//dropSchema: true,
});
});
...
...
@@ -121,7 +121,12 @@ describe('Koishi typeorm', () => {
expect
(
app
.
typeorm
.
getRepository
(
User
)).
toBeUndefined
();
});
afterEach
(
async
()
=>
{
await
app
.
stop
();
it
(
'
should reload the same connection
'
,
async
()
=>
{
await
app
.
typeorm
.
create
(
'
yuzu
'
,
[
User
,
Book
]);
expect
(
app
.
typeorm
.
getConnection
(
'
yuzu
'
)).
toBeInstanceOf
(
Connection
);
await
app
.
typeorm
.
close
(
'
yuzu
'
);
expect
(
app
.
typeorm
.
getConnection
(
'
yuzu
'
)).
toBeUndefined
();
await
app
.
typeorm
.
create
(
'
yuzu
'
,
[
User
,
Book
]);
expect
(
app
.
typeorm
.
getConnection
(
'
yuzu
'
)).
toBeInstanceOf
(
Connection
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment