Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-entities
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-entities
Commits
79a9f00f
Commit
79a9f00f
authored
Mar 28, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refname type
parent
b2e76bbe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
9 deletions
+9
-9
src/decorators.ts
src/decorators.ts
+3
-3
src/def/def.ts
src/def/def.ts
+1
-1
src/meta/def.ts
src/meta/def.ts
+2
-2
src/register.ts
src/register.ts
+3
-3
No files found.
src/decorators.ts
View file @
79a9f00f
import
{
ClassType
,
ModelFieldDef
,
PrimaryKey
Def
}
from
'
./def
'
;
import
{
ModelClassType
,
ModelField
Def
}
from
'
./def
'
;
import
{
Metadata
}
from
'
./meta/meta
'
;
import
{
Metadata
}
from
'
./meta/meta
'
;
import
{
Flatten
,
Keys
,
Model
,
Tables
}
from
'
koishi
'
;
import
{
Flatten
,
Keys
,
Tables
}
from
'
koishi
'
;
import
{
inferType
}
from
'
./utils
'
;
import
{
inferType
}
from
'
./utils
'
;
export
const
DefineModel
=
(
name
:
Keys
<
Tables
>
):
ClassDecorator
=>
export
const
DefineModel
=
(
name
:
Keys
<
Tables
>
):
ClassDecorator
=>
...
@@ -32,7 +32,7 @@ export const Unique = (
...
@@ -32,7 +32,7 @@ export const Unique = (
):
PropertyDecorator
=>
Metadata
.
append
(
'
ModelUnique
'
,
identifier
);
):
PropertyDecorator
=>
Metadata
.
append
(
'
ModelUnique
'
,
identifier
);
export
const
ChildModel
=
export
const
ChildModel
=
(
cls
?:
ClassType
):
PropertyDecorator
=>
(
cls
?:
Model
ClassType
):
PropertyDecorator
=>
(
obj
,
key
)
=>
{
(
obj
,
key
)
=>
{
if
(
!
cls
)
{
if
(
!
cls
)
{
cls
=
Reflect
.
getMetadata
(
'
design:type
'
,
obj
,
key
);
cls
=
Reflect
.
getMetadata
(
'
design:type
'
,
obj
,
key
);
...
...
src/def/def.ts
View file @
79a9f00f
...
@@ -4,7 +4,7 @@ export type ModelFieldDef<T = any> =
...
@@ -4,7 +4,7 @@ export type ModelFieldDef<T = any> =
|
Model
.
Field
<
T
>
|
Model
.
Field
<
T
>
|
Model
.
Field
.
Shorthand
<
Model
.
Field
.
Type
<
T
>>
;
|
Model
.
Field
.
Shorthand
<
Model
.
Field
.
Type
<
T
>>
;
export
type
ClassType
<
T
=
any
>
=
{
new
(...
args
:
any
[]):
T
};
export
type
Model
ClassType
<
T
=
any
>
=
{
new
(...
args
:
any
[]):
T
};
export
interface
PrimaryKeyDef
{
export
interface
PrimaryKeyDef
{
autoIncrement
:
boolean
;
autoIncrement
:
boolean
;
...
...
src/meta/def.ts
View file @
79a9f00f
import
{
ClassType
,
ModelFieldDef
,
PrimaryKeyDef
}
from
'
../def
'
;
import
{
Model
ClassType
,
ModelFieldDef
,
PrimaryKeyDef
}
from
'
../def
'
;
import
{
Keys
,
Tables
}
from
'
koishi
'
;
import
{
Keys
,
Tables
}
from
'
koishi
'
;
export
interface
MetadataArrayMap
{
export
interface
MetadataArrayMap
{
...
@@ -12,5 +12,5 @@ export interface MetadataMap {
...
@@ -12,5 +12,5 @@ export interface MetadataMap {
ModelTableName
:
Keys
<
Tables
>
;
ModelTableName
:
Keys
<
Tables
>
;
ModelPrimaryKey
:
PrimaryKeyDef
;
ModelPrimaryKey
:
PrimaryKeyDef
;
ModelForeignKey
:
[
string
,
string
];
ModelForeignKey
:
[
string
,
string
];
ChildModel
:
ClassType
;
ChildModel
:
Model
ClassType
;
}
}
src/register.ts
View file @
79a9f00f
import
{
Context
,
Keys
,
Model
}
from
'
koishi
'
;
import
{
Context
,
Keys
,
Model
}
from
'
koishi
'
;
import
{
ClassType
}
from
'
./def
'
;
import
{
Model
ClassType
}
from
'
./def
'
;
import
{
reflector
}
from
'
./meta/meta
'
;
import
{
reflector
}
from
'
./meta/meta
'
;
class
ModelRegistrar
<
T
=
any
>
{
class
ModelRegistrar
<
T
=
any
>
{
constructor
(
private
cls
:
ClassType
<
T
>
,
private
prefix
=
''
)
{}
constructor
(
private
cls
:
Model
ClassType
<
T
>
,
private
prefix
=
''
)
{}
getTableName
()
{
getTableName
()
{
return
reflector
.
get
(
'
ModelTableName
'
,
this
.
cls
);
return
reflector
.
get
(
'
ModelTableName
'
,
this
.
cls
);
...
@@ -106,7 +106,7 @@ class ModelRegistrar<T = any> {
...
@@ -106,7 +106,7 @@ class ModelRegistrar<T = any> {
getChildDict
()
{
getChildDict
()
{
const
keys
=
reflector
.
getArray
(
'
ChildModelKeys
'
,
this
.
cls
);
const
keys
=
reflector
.
getArray
(
'
ChildModelKeys
'
,
this
.
cls
);
const
result
:
{
[
K
in
keyof
T
]?:
ClassType
<
T
>
}
=
{};
const
result
:
{
[
K
in
keyof
T
]?:
Model
ClassType
<
T
>
}
=
{};
for
(
const
key
of
keys
)
{
for
(
const
key
of
keys
)
{
const
child
=
reflector
.
get
(
'
ChildModel
'
,
this
.
cls
,
key
);
const
child
=
reflector
.
get
(
'
ChildModel
'
,
this
.
cls
,
key
);
if
(
child
)
{
if
(
child
)
{
...
...
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