Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
I
init-things
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
nanahira
init-things
Commits
8c937300
Commit
8c937300
authored
Aug 17, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postgres and abandon nest-koishijs
parent
49e26b35
Pipeline
#4736
passed with stages
in 1 minute and 9 seconds
Changes
27
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
29 additions
and
1256 deletions
+29
-1256
things/nest-koishijs/.dockerignore
things/nest-koishijs/.dockerignore
+0
-42
things/nest-koishijs/.gitignore
things/nest-koishijs/.gitignore
+0
-38
things/nest-koishijs/.gitlab-ci.yml
things/nest-koishijs/.gitlab-ci.yml
+0
-64
things/nest-koishijs/.npmignore
things/nest-koishijs/.npmignore
+0
-8
things/nest-koishijs/Dockerfile
things/nest-koishijs/Dockerfile
+0
-11
things/nest-koishijs/LICENSE
things/nest-koishijs/LICENSE
+0
-661
things/nest-koishijs/README.md
things/nest-koishijs/README.md
+0
-36
things/nest-koishijs/install-npm.sh
things/nest-koishijs/install-npm.sh
+0
-18
things/nest-koishijs/nest-cli.json
things/nest-koishijs/nest-cli.json
+0
-7
things/nest-koishijs/src/app.controller.spec.ts
things/nest-koishijs/src/app.controller.spec.ts
+0
-22
things/nest-koishijs/src/app.module.ts
things/nest-koishijs/src/app.module.ts
+0
-13
things/nest-koishijs/src/app.service.ts
things/nest-koishijs/src/app.service.ts
+0
-19
things/nest-koishijs/src/bot/bot.service.spec.ts
things/nest-koishijs/src/bot/bot.service.spec.ts
+0
-18
things/nest-koishijs/src/bot/bot.service.ts
things/nest-koishijs/src/bot/bot.service.ts
+0
-113
things/nest-koishijs/src/config.ts
things/nest-koishijs/src/config.ts
+0
-22
things/nest-koishijs/src/dto/ReturnMessage.dto.ts
things/nest-koishijs/src/dto/ReturnMessage.dto.ts
+0
-29
things/nest-koishijs/src/entities/Group.entity.ts
things/nest-koishijs/src/entities/Group.entity.ts
+0
-5
things/nest-koishijs/src/entities/QQIDBase.entity.ts
things/nest-koishijs/src/entities/QQIDBase.entity.ts
+0
-7
things/nest-koishijs/src/entities/TimeBase.entity.ts
things/nest-koishijs/src/entities/TimeBase.entity.ts
+0
-16
things/nest-koishijs/src/entities/User.entity.ts
things/nest-koishijs/src/entities/User.entity.ts
+0
-9
things/nest-koishijs/src/main.ts
things/nest-koishijs/src/main.ts
+0
-22
things/nest-koishijs/test/app.e2e-spec.ts
things/nest-koishijs/test/app.e2e-spec.ts
+0
-24
things/nest-koishijs/test/jest-e2e.json
things/nest-koishijs/test/jest-e2e.json
+0
-9
things/nest-koishijs/tsconfig.json
things/nest-koishijs/tsconfig.json
+0
-18
things/nest-typeorm/install-npm.sh
things/nest-typeorm/install-npm.sh
+5
-2
things/nest-typeorm/src/app.module.ts
things/nest-typeorm/src/app.module.ts
+24
-2
things/nest-typeorm/src/config.ts
things/nest-typeorm/src/config.ts
+0
-21
No files found.
things/nest-koishijs/.dockerignore
deleted
100644 → 0
View file @
49e26b35
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
.git*
Dockerfile
.dockerignore
things/nest-koishijs/.gitignore
deleted
100644 → 0
View file @
49e26b35
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
things/nest-koishijs/.gitlab-ci.yml
deleted
100644 → 0
View file @
49e26b35
stages
:
-
build
-
combine
-
deploy
variables
:
GIT_DEPTH
:
"
1"
CONTAINER_TEST_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_TEST_ARM_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
CONTAINER_TEST_X86_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
CONTAINER_RELEASE_IMAGE
:
$CI_REGISTRY_IMAGE:latest
before_script
:
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build-x86
:
stage
:
build
tags
:
-
docker
script
:
-
docker build --pull -t $CONTAINER_TEST_X86_IMAGE .
-
docker push $CONTAINER_TEST_X86_IMAGE
build-arm
:
stage
:
build
tags
:
-
docker-arm
script
:
-
docker build --pull -t $CONTAINER_TEST_ARM_IMAGE .
-
docker push $CONTAINER_TEST_ARM_IMAGE
combine
:
stage
:
combine
tags
:
-
docker
script
:
-
docker pull $CONTAINER_TEST_X86_IMAGE
-
docker pull $CONTAINER_TEST_ARM_IMAGE
-
docker manifest create $CONTAINER_TEST_IMAGE --amend $CONTAINER_TEST_X86_IMAGE --amend $CONTAINER_TEST_ARM_IMAGE
-
docker manifest push $CONTAINER_TEST_IMAGE
deploy_latest
:
stage
:
deploy
tags
:
-
docker
script
:
-
docker pull $CONTAINER_TEST_IMAGE
-
docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
-
docker push $CONTAINER_RELEASE_IMAGE
only
:
-
master
deploy_tag
:
stage
:
deploy
tags
:
-
docker
variables
:
CONTAINER_TAG_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script
:
-
docker pull $CONTAINER_TEST_IMAGE
-
docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
-
docker push $CONTAINER_TAG_IMAGE
only
:
-
tags
things/nest-koishijs/.npmignore
deleted
100644 → 0
View file @
49e26b35
/install-npm.sh
.git*
/output
/dest
/config.yaml
.idea
.dockerignore
Dockerfile
\ No newline at end of file
things/nest-koishijs/Dockerfile
deleted
100644 → 0
View file @
49e26b35
FROM
node:bullseye-slim
LABEL
Author="Nanahira <nanahira@momobako.com>"
RUN
apt update
&&
apt
-y
install
python3 build-essential
&&
rm
-rf
/var/lib/apt/lists/
*
/tmp/
*
/var/tmp/
*
WORKDIR
/usr/src/app
COPY
./package*.json ./
RUN
npm ci
COPY
. ./
RUN
npm run build
CMD
["npm", "run", "start:prod"]
things/nest-koishijs/LICENSE
deleted
100644 → 0
View file @
49e26b35
This diff is collapsed.
Click to expand it.
things/nest-koishijs/README.md
deleted
100644 → 0
View file @
49e26b35
# App name
App description.
## Environment
*
`DB_HOST`
`DB_PORT`
`DB_USER`
`DB_PASS`
`DB_NAME`
Database configs.
*
`CQ_ID`
QQ account.
*
`CQ_SERVER`
OneBot server address.
*
`CQ_TOKEN`
OneBot server token.
## Installation
```
bash
$
npm
install
```
## Running the app
```
bash
# development
$
npm run start
# watch mode
$
npm run start:dev
# production mode
$
npm run start:prod
```
## License
AGPLv3
things/nest-koishijs/install-npm.sh
deleted
100755 → 0
View file @
49e26b35
#!/bin/bash
npm
install
--save
\
class-validator
\
class-transformer
\
@nestjs/swagger
\
swagger-ui-express
\
lodash
\
typeorm
\
@nestjs/typeorm
\
mysql
\
reflect-metadata
\
koishi
\
koishi-adapter-onebot
\
koishi-plugin-common
npm
install
--save-dev
\
@types/lodash
\
@types/express
things/nest-koishijs/nest-cli.json
deleted
100644 → 0
View file @
49e26b35
{
"collection"
:
"@nestjs/schematics"
,
"sourceRoot"
:
"src"
,
"compilerOptions"
:
{
"plugins"
:
[
"@nestjs/swagger"
]
}
}
things/nest-koishijs/src/app.controller.spec.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
describe
(
'
AppController
'
,
()
=>
{
let
appController
:
AppController
;
beforeEach
(
async
()
=>
{
const
app
:
TestingModule
=
await
Test
.
createTestingModule
({
controllers
:
[
AppController
],
providers
:
[
AppService
],
}).
compile
();
appController
=
app
.
get
<
AppController
>
(
AppController
);
});
describe
(
'
root
'
,
()
=>
{
it
(
'
should be defined
'
,
()
=>
{
expect
(
appController
).
toBeDefined
();
});
});
});
things/nest-koishijs/src/app.module.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
import
{
typeormConfig
}
from
'
./config
'
;
import
{
BotService
}
from
'
./bot/bot.service
'
;
@
Module
({
imports
:
[
TypeOrmModule
.
forRoot
(
typeormConfig
())],
controllers
:
[
AppController
],
providers
:
[
AppService
,
BotService
],
})
export
class
AppModule
{}
things/nest-koishijs/src/app.service.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Injectable
,
ConsoleLogger
}
from
'
@nestjs/common
'
;
import
{
Connection
}
from
'
typeorm
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
BotService
}
from
'
./bot/bot.service
'
;
@
Injectable
()
export
class
AppService
extends
ConsoleLogger
{
constructor
(
@
InjectConnection
(
'
app
'
)
private
db
:
Connection
,
private
botService
:
BotService
)
{
super
(
'
app
'
,
true
)
}
getHello
():
string
{
return
'
Hello World!
'
;
}
}
things/nest-koishijs/src/bot/bot.service.spec.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
BotService
}
from
'
./bot.service
'
;
describe
(
'
BotService
'
,
()
=>
{
let
service
:
BotService
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
providers
:
[
BotService
],
}).
compile
();
service
=
module
.
get
<
BotService
>
(
BotService
);
});
it
(
'
should be defined
'
,
()
=>
{
expect
(
service
).
toBeDefined
();
});
});
things/nest-koishijs/src/bot/bot.service.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Injectable
,
ConsoleLogger
}
from
'
@nestjs/common
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
Connection
}
from
'
typeorm
'
;
import
{
User
}
from
'
../entities/User.entity
'
;
import
{
Group
}
from
'
../entities/Group.entity
'
;
import
{
App
,
AppConfig
}
from
'
koishi
'
;
import
{
AppService
}
from
'
../app.service
'
;
import
*
as
koishiCommonPlugin
from
'
koishi-plugin-common
'
;
import
*
as
adapter
from
'
koishi-adapter-onebot
'
;
import
{
CQBot
}
from
'
koishi-adapter-onebot
'
;
const
__
=
typeof
adapter
;
// just for import
@
Injectable
()
export
class
BotService
extends
ConsoleLogger
{
bot
:
App
;
botConfig
:
AppConfig
;
constructor
(
@
InjectConnection
(
'
app
'
)
private
db
:
Connection
,
private
readonly
appService
:
AppService
,
)
{
super
(
'
bot
'
);
this
.
initializeBot
();
}
async
initializeBot
()
{
this
.
botConfig
=
{
type
:
'
onebot:ws
'
,
selfId
:
process
.
env
.
CQ_ID
,
server
:
process
.
env
.
CQ_SERVER
,
token
:
process
.
env
.
CQ_TOKEN
,
prefix
:
process
.
env
.
CQ_PREFIX
||
'
.
'
,
};
this
.
bot
=
new
App
(
this
.
botConfig
);
this
.
bot
.
plugin
(
koishiCommonPlugin
,
{
onFriendRequest
:
true
,
});
this
.
loadBotRouters
();
await
this
.
bot
.
start
();
this
.
log
.
log
(
`Bot started.`
);
}
loadBotRouters
()
{
// all middlewares should be here.
this
.
bot
.
command
(
'
echo <msg:text>
'
).
action
((
argv
,
msg
)
=>
{
return
msg
;
});
}
async
findOrCreateUser
(
id
:
string
,
name
?:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
User
);
let
ent
=
await
repo
.
findOne
({
where
:
{
id
}
});
if
(
ent
)
{
if
(
!
ent
.
name
&&
name
)
{
ent
.
name
=
name
;
return
await
repo
.
save
(
ent
);
}
else
{
return
ent
;
}
}
ent
=
new
User
();
ent
.
id
=
id
;
ent
.
name
=
name
;
try
{
ent
=
await
repo
.
save
(
ent
);
}
catch
(
e
)
{
this
.
log
.
error
(
`Failed to save user
${
id
}
:
${
e
.
toString
()}
`
);
return
null
;
}
return
ent
;
}
async
findOrCreateGroup
(
id
:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
Group
);
let
ent
=
await
repo
.
findOne
({
where
:
{
id
}
});
if
(
ent
)
{
return
ent
;
}
ent
=
new
Group
();
ent
.
id
=
id
;
try
{
ent
=
await
repo
.
save
(
ent
);
}
catch
(
e
)
{
this
.
log
.
error
(
`Failed to save group
${
id
}
:
${
e
.
toString
()}
`
);
return
null
;
}
return
ent
;
}
getBot
()
{
return
(
this
.
bot
.
bots
[
0
]
as
unknown
)
as
CQBot
;
}
async
sendPrivateMessage
(
id
:
string
,
message
:
string
)
{
try
{
await
this
.
getBot
().
$sendPrivateMsg
(
id
,
message
);
return
true
;
}
catch
(
e
)
{
this
.
log
.
error
(
`Failed to send private message
${
message
}
to
${
id
}
:
${
e
.
toString
()}
`
,
);
return
false
;
}
}
async
sendGroupMessage
(
id
:
string
,
message
:
string
)
{
try
{
await
this
.
getBot
().
$sendGroupMsg
(
id
,
message
);
return
true
;
}
catch
(
e
)
{
this
.
log
.
error
(
`Failed to send group message
${
message
}
to
${
id
}
:
${
e
.
toString
()}
`
,
);
return
false
;
}
}
}
things/nest-koishijs/src/config.ts
deleted
100644 → 0
View file @
49e26b35
import
{
TypeOrmModuleOptions
}
from
'
@nestjs/typeorm
'
;
import
{
User
}
from
'
./entities/User.entity
'
;
import
{
Group
}
from
'
./entities/Group.entity
'
;
export
function
dbConfig
()
{
return
{
host
:
process
.
env
.
DB_HOST
,
port
:
process
.
env
.
DB_PORT
?
parseInt
(
process
.
env
.
DB_PORT
)
:
3306
,
username
:
process
.
env
.
DB_USER
,
password
:
process
.
env
.
DB_PASS
,
database
:
process
.
env
.
DB_NAME
,
};
}
export
function
typeormConfig
():
TypeOrmModuleOptions
{
return
{
name
:
'
app
'
,
type
:
'
mysql
'
,
entities
:
[
User
,
Group
],
// entities here
synchronize
:
true
,
...
dbConfig
(),
};
}
things/nest-koishijs/src/dto/ReturnMessage.dto.ts
deleted
100644 → 0
View file @
49e26b35
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
export
class
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回状态
'
})
statusCode
:
number
;
@
ApiProperty
({
description
:
'
返回信息
'
})
message
:
string
;
@
ApiProperty
({
description
:
'
是否成功
'
})
success
:
boolean
;
constructor
(
statusCode
:
number
,
message
?:
string
)
{
this
.
statusCode
=
statusCode
;
this
.
message
=
message
||
'
success
'
;
this
.
success
=
statusCode
<
400
;
}
toException
()
{
return
new
HttpException
(
this
,
this
.
statusCode
);
}
}
export
class
ReturnMessageDto
<
T
>
extends
BlankReturnMessageDto
{
@
ApiProperty
({
description
:
'
返回内容
'
})
data
?:
T
;
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
T
)
{
super
(
statusCode
,
message
);
this
.
data
=
data
;
}
}
things/nest-koishijs/src/entities/Group.entity.ts
deleted
100644 → 0
View file @
49e26b35
import
{
QQIDBase
}
from
'
./QQIDBase.entity
'
;
import
{
Entity
}
from
'
typeorm
'
;
@
Entity
()
export
class
Group
extends
QQIDBase
{}
things/nest-koishijs/src/entities/QQIDBase.entity.ts
deleted
100644 → 0
View file @
49e26b35
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
import
{
Column
,
Index
,
PrimaryColumn
}
from
'
typeorm
'
;
export
class
QQIDBase
extends
TimeBase
{
@
PrimaryColumn
(
'
varchar
'
,
{
length
:
12
})
id
:
string
;
}
things/nest-koishijs/src/entities/TimeBase.entity.ts
deleted
100644 → 0
View file @
49e26b35
import
{
CreateDateColumn
,
UpdateDateColumn
}
from
'
typeorm
'
;
import
{
Exclude
}
from
'
class-transformer
'
;
export
class
TimeBase
{
@
CreateDateColumn
({
select
:
false
})
@
Exclude
()
createTime
:
Date
;
@
UpdateDateColumn
({
select
:
false
})
@
Exclude
()
updateTime
:
Date
;
toObject
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
this
));
}
}
things/nest-koishijs/src/entities/User.entity.ts
deleted
100644 → 0
View file @
49e26b35
import
{
QQIDBase
}
from
'
./QQIDBase.entity
'
;
import
{
Column
,
Entity
,
Index
}
from
'
typeorm
'
;
@
Entity
()
export
class
User
extends
QQIDBase
{
@
Index
()
@
Column
(
'
varchar
'
,
{
length
:
32
,
nullable
:
true
})
name
:
string
;
}
things/nest-koishijs/src/main.ts
deleted
100644 → 0
View file @
49e26b35
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
SwaggerModule
,
DocumentBuilder
}
from
'
@nestjs/swagger
'
;
import
{
NestExpressApplication
}
from
'
@nestjs/platform-express
'
;
import
{
AppModule
}
from
'
./app.module
'
;
async
function
bootstrap
()
{
const
app
=
await
NestFactory
.
create
<
NestExpressApplication
>
(
AppModule
);
app
.
enableCors
();
app
.
set
(
'
trust proxy
'
,
[
'
172.16.0.0/12
'
,
'
loopback
'
]);
const
documentConfig
=
new
DocumentBuilder
()
.
setTitle
(
'
app
'
)
.
setDescription
(
'
The app
'
)
.
setVersion
(
'
1.0
'
)
.
build
();
const
document
=
SwaggerModule
.
createDocument
(
app
,
documentConfig
);
SwaggerModule
.
setup
(
'
docs
'
,
app
,
document
);
await
app
.
listen
(
3000
);
}
bootstrap
();
things/nest-koishijs/test/app.e2e-spec.ts
deleted
100644 → 0
View file @
49e26b35
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
INestApplication
}
from
'
@nestjs/common
'
;
import
*
as
request
from
'
supertest
'
;
import
{
AppModule
}
from
'
./../src/app.module
'
;
describe
(
'
AppController (e2e)
'
,
()
=>
{
let
app
:
INestApplication
;
beforeEach
(
async
()
=>
{
const
moduleFixture
:
TestingModule
=
await
Test
.
createTestingModule
({
imports
:
[
AppModule
],
}).
compile
();
app
=
moduleFixture
.
createNestApplication
();
await
app
.
init
();
});
/* it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
}); */
});
things/nest-koishijs/test/jest-e2e.json
deleted
100644 → 0
View file @
49e26b35
{
"moduleFileExtensions"
:
[
"js"
,
"json"
,
"ts"
],
"rootDir"
:
"."
,
"testEnvironment"
:
"node"
,
"testRegex"
:
".e2e-spec.ts$"
,
"transform"
:
{
"^.+\\.(t|j)s$"
:
"ts-jest"
}
}
things/nest-koishijs/tsconfig.json
deleted
100644 → 0
View file @
49e26b35
{
"compilerOptions"
:
{
"module"
:
"commonjs"
,
"declaration"
:
true
,
"removeComments"
:
true
,
"emitDecoratorMetadata"
:
true
,
"experimentalDecorators"
:
true
,
"allowSyntheticDefaultImports"
:
true
,
"target"
:
"es2017"
,
"sourceMap"
:
true
,
"outDir"
:
"./dist"
,
"baseUrl"
:
"./"
,
"incremental"
:
true
,
"esModuleInterop"
:
true
},
"compileOnSave"
:
true
,
"allowJs"
:
true
}
things/nest-typeorm/install-npm.sh
View file @
8c937300
...
...
@@ -7,9 +7,12 @@ npm install --save \
lodash
\
typeorm
\
@nestjs/typeorm
\
mysql
\
@nestjs/config
\
pg
\
pg-native
\
reflect-metadata
npm
install
--save-dev
\
@types/lodash
\
@types/express
@types/express
\
@types/multer
things/nest-typeorm/src/app.module.ts
View file @
8c937300
...
...
@@ -2,10 +2,32 @@ import { Module } from '@nestjs/common';
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
import
{
typeormConfig
}
from
'
./config
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
User
}
from
'
./entities/User.entity
'
;
const
configModule
=
ConfigModule
.
forRoot
();
@
Module
({
imports
:
[
TypeOrmModule
.
forRoot
(
typeormConfig
())],
imports
:
[
configModule
,
TypeOrmModule
.
forRootAsync
({
imports
:
[
configModule
],
inject
:
[
ConfigService
],
useFactory
:
async
(
config
:
ConfigService
)
=>
{
return
{
name
:
'
app
'
,
type
:
'
postgres
'
,
entities
:
[
User
],
// entities here
synchronize
:
true
,
host
:
config
.
get
(
'
DB_HOST
'
),
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
username
:
config
.
get
(
'
DB_USER
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
};
},
}),
],
controllers
:
[
AppController
],
providers
:
[
AppService
],
})
...
...
things/nest-typeorm/src/config.ts
deleted
100644 → 0
View file @
49e26b35
import
{
TypeOrmModuleOptions
}
from
'
@nestjs/typeorm
'
;
import
{
User
}
from
'
./entities/User.entity
'
;
export
function
dbConfig
()
{
return
{
host
:
process
.
env
.
DB_HOST
,
port
:
process
.
env
.
DB_PORT
?
parseInt
(
process
.
env
.
DB_PORT
)
:
3306
,
username
:
process
.
env
.
DB_USER
,
password
:
process
.
env
.
DB_PASS
,
database
:
process
.
env
.
DB_NAME
,
};
}
export
function
typeormConfig
():
TypeOrmModuleOptions
{
return
{
name
:
'
app
'
,
type
:
'
mysql
'
,
entities
:
[
User
],
// entities here
synchronize
:
true
,
...
dbConfig
(),
};
}
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