Skip to content

Commit b3e8649

Browse files
authored
Use mongodb URI (#16)
* Use mongodb URI * CHANGELOG.md
1 parent 5552fbd commit b3e8649

12 files changed

Lines changed: 37 additions & 25 deletions

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ DATABASE_NAME=ink
1313
DATABASE_USERNAME=mongodb
1414
DATABASE_PASSWORD=mongodb
1515
DATABASE_PORT=27017
16-
DATABASE_SSL_CA=""
1716
DATABASE_RETRY_ATTEMPTS=5
1817
DATABASE_RETRY_DELAY=3000
18+
DATABASE_URI=
1919

2020
WS_PROVIDER=wss://rococo-contracts-rpc.polkadot.io
2121
LOAD_ALL_BLOCKS=false

.env.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DATABASE_NAME=ink
1111
DATABASE_USERNAME=root
1212
DATABASE_PASSWORD=password
1313
DATABASE_PORT=5432
14-
DATABASE_SSL_CA=""
14+
DATABASE_URI=""
1515
DATABASE_RETRY_ATTEMPTS=5
1616
DATABASE_RETRY_DELAY=3000
1717
WS_PROVIDER=ws://127.0.0.1:9944

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.1
4+
Published by **[blockcoders](https://github.com/blockcoders)** on **2022/12/09**
5+
- [#16](https://github.com/blockcoders/nestjs-ethers/pull/16) Use mongodb URI
6+
37
## 1.1.0
48
Published by **[blockcoders](https://github.com/blockcoders)** on **2022/12/09**
59
- [#15](https://github.com/blockcoders/nestjs-ethers/pull/15) Migrate to mongodb

README-es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ query {
229229
```graphql
230230
{
231231
"data": {
232-
"version": "v1.1.0"
232+
"version": "v1.1.1"
233233
}
234234
}
235235
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ query {
229229
```graphql
230230
{
231231
"data": {
232-
"version": "v1.1.0"
232+
"version": "v1.1.1"
233233
}
234234
}
235235
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ink-substrate-explorer-api",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains.",
55
"author": "Blockcoders <engineering@blockcoders.io>",
66
"license": "MIT",

src/app.resolver.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('AppResolver', () => {
2424

2525
describe('version', () => {
2626
it('should return the current version', () => {
27-
expect(resolver.version()).toEqual('v1.1.0')
27+
expect(resolver.version()).toEqual('v1.1.1')
2828
})
2929
})
3030
})

src/app.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export class AppResolver {
99

1010
@Query(/* istanbul ignore next */ () => String)
1111
version(): string {
12-
return 'v1.1.0'
12+
return 'v1.1.1'
1313
}
1414
}

src/db/db.module.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ import { DbService } from './db.service'
1818
useFactory: async (env: EnvService) => {
1919
const config: TypeOrmModuleOptions = {
2020
type: 'mongodb',
21-
host: env.DATABASE_HOST,
22-
port: env.DATABASE_PORT,
23-
username: env.DATABASE_USERNAME,
24-
password: env.DATABASE_PASSWORD,
25-
database: env.DATABASE_NAME,
2621
retryAttempts: env.DATABASE_RETRY_ATTEMPTS,
2722
retryDelay: env.DATABASE_RETRY_DELAY,
2823
synchronize: true,
2924
autoLoadEntities: true,
3025
keepConnectionAlive: false,
3126
}
3227

33-
if (!env.DATABASE_SSL_CA) {
34-
return config
28+
if (env.DATABASE_URI) {
29+
return {
30+
...config,
31+
url: env.DATABASE_URI,
32+
}
3533
}
3634

3735
return {
3836
...config,
39-
sslCA: env.DATABASE_SSL_CA,
37+
host: env.DATABASE_HOST,
38+
port: env.DATABASE_PORT,
39+
username: env.DATABASE_USERNAME,
40+
password: env.DATABASE_PASSWORD,
41+
database: env.DATABASE_NAME,
4042
}
4143
},
4244
}),

src/db/db.service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ export class DbService {
1212
) {}
1313

1414
async addIndexes() {
15-
const host = this.env.DATABASE_HOST
16-
const port = this.env.DATABASE_PORT
17-
const username = this.env.DATABASE_USERNAME
18-
const password = this.env.DATABASE_PASSWORD
19-
const database = this.env.DATABASE_NAME
20-
21-
const con = await mongoose.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`)
15+
let con: typeof mongoose
16+
17+
if (this.env.DATABASE_URI) {
18+
con = await mongoose.connect(this.env.DATABASE_URI)
19+
} else {
20+
const host = this.env.DATABASE_HOST
21+
const port = this.env.DATABASE_PORT
22+
const username = this.env.DATABASE_USERNAME
23+
const password = this.env.DATABASE_PASSWORD
24+
const database = this.env.DATABASE_NAME
25+
26+
con = await mongoose.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`)
27+
}
2228

2329
// block indexes
2430
const blocks = con.connection.collection('blocks')

0 commit comments

Comments
 (0)