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
d0c44370
Commit
d0c44370
authored
Feb 10, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix multi conn conflict
parent
17fbe4af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
src/index.ts
src/index.ts
+1
-0
tests/typeorm.spec.ts
tests/typeorm.spec.ts
+30
-3
No files found.
src/index.ts
View file @
d0c44370
...
@@ -83,6 +83,7 @@ export default class TypeORMPlugin extends BasePlugin<TypeORMPluginConfigLike> {
...
@@ -83,6 +83,7 @@ export default class TypeORMPlugin extends BasePlugin<TypeORMPluginConfigLike> {
entities
,
entities
,
entityPrefix
:
`koishi_
${
token
}
_`
,
entityPrefix
:
`koishi_
${
token
}
_`
,
metadataTableName
:
`koishi_typeorm_metadata_
${
token
}
`
,
metadataTableName
:
`koishi_typeorm_metadata_
${
token
}
`
,
name
:
`koishi_
${
token
}
`
,
...
extraOptions
,
...
extraOptions
,
};
};
const
connection
=
await
createConnection
(
connectionOptions
);
const
connection
=
await
createConnection
(
connectionOptions
);
...
...
tests/typeorm.spec.ts
View file @
d0c44370
...
@@ -33,6 +33,14 @@ class Book {
...
@@ -33,6 +33,14 @@ class Book {
author
:
User
;
author
:
User
;
}
}
@
Entity
()
class
Magic
{
@
PrimaryGeneratedColumn
()
id
:
number
;
@
Column
(
'
varchar
'
,
{
length
:
32
})
name
:
string
;
}
describe
(
'
Koishi typeorm
'
,
()
=>
{
describe
(
'
Koishi typeorm
'
,
()
=>
{
let
app
:
App
;
let
app
:
App
;
...
@@ -46,7 +54,7 @@ describe('Koishi typeorm', () => {
...
@@ -46,7 +54,7 @@ describe('Koishi typeorm', () => {
username
:
'
koishi
'
,
username
:
'
koishi
'
,
password
:
'
koishi@114514
'
,
password
:
'
koishi@114514
'
,
database
:
'
koishi
'
,
database
:
'
koishi
'
,
dropSchema
:
true
,
//
dropSchema: true,
});
});
});
});
...
@@ -67,12 +75,27 @@ describe('Koishi typeorm', () => {
...
@@ -67,12 +75,27 @@ describe('Koishi typeorm', () => {
expect
(
gotUser
.
name
).
toBe
(
'
Shigma
'
);
expect
(
gotUser
.
name
).
toBe
(
'
Shigma
'
);
});
});
it
(
'
should able to open more than 1 connection
'
,
async
()
=>
{
await
app
.
typeorm
.
create
(
'
fooo
'
,
[
User
,
Book
]);
await
app
.
typeorm
.
create
(
'
barr
'
,
[
Magic
]);
const
connection1
=
app
.
typeorm
.
getConnection
(
'
fooo
'
);
const
connection2
=
app
.
typeorm
.
getConnection
(
'
barr
'
);
expect
(
connection1
).
toBeInstanceOf
(
Connection
);
expect
(
connection2
).
toBeInstanceOf
(
Connection
);
const
userRepo
=
app
.
typeorm
.
getRepository
(
User
);
const
magicRepo
=
app
.
typeorm
.
getRepository
(
Magic
);
expect
(
userRepo
).
toBeInstanceOf
(
Repository
);
expect
(
magicRepo
).
toBeInstanceOf
(
Repository
);
expect
(
userRepo
.
manager
).
toEqual
(
connection1
.
manager
);
expect
(
magicRepo
.
manager
).
toEqual
(
connection2
.
manager
);
});
it
(
'
should connect with custom options
'
,
async
()
=>
{
it
(
'
should connect with custom options
'
,
async
()
=>
{
await
app
.
typeorm
.
create
(
'
foo
'
,
[
User
,
Book
],
{
await
app
.
typeorm
.
create
(
'
baz
'
,
[
User
,
Book
],
{
entityPrefix
:
'
fooooo_
'
,
entityPrefix
:
'
fooooo_
'
,
metadataTableName
:
'
fooooo_metadata
'
,
metadataTableName
:
'
fooooo_metadata
'
,
});
});
const
connection
=
app
.
typeorm
.
getConnection
(
'
foo
'
);
const
connection
=
app
.
typeorm
.
getConnection
(
'
baz
'
);
expect
(
connection
.
metadataTableName
).
toBe
(
'
fooooo_metadata
'
);
expect
(
connection
.
metadataTableName
).
toBe
(
'
fooooo_metadata
'
);
});
});
...
@@ -97,4 +120,8 @@ describe('Koishi typeorm', () => {
...
@@ -97,4 +120,8 @@ describe('Koishi typeorm', () => {
expect
(
app
.
typeorm
.
getConnection
(
'
bar
'
)).
toBeUndefined
();
expect
(
app
.
typeorm
.
getConnection
(
'
bar
'
)).
toBeUndefined
();
expect
(
app
.
typeorm
.
getRepository
(
User
)).
toBeUndefined
();
expect
(
app
.
typeorm
.
getRepository
(
User
)).
toBeUndefined
();
});
});
afterEach
(
async
()
=>
{
await
app
.
stop
();
});
});
});
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