Skip to content

Commit 6de46a2

Browse files
authored
Add possibility to use MongoDB as database (jhipster#717)
Add possibility to use MongoDB as database (jhipster#717)
1 parent a24d6a7 commit 6de46a2

File tree

74 files changed

+1595
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1595
-126
lines changed

.github/workflows/test-integration-jwt.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- jwt-with-blazor-cqrs-app
1919
- jwt-with-mssql-app
2020
- jwt-with-mysql-app
21+
- jwt-with-mongo-app
22+
- jwt-with-mongo-cqrs-app
2123
- jwt-with-postgres-app
2224
- jwt-with-react-app
2325
- jwt-with-vue-app
@@ -34,6 +36,10 @@ jobs:
3436
arg: 'no'
3537
- app-type: jwt-with-mysql-app
3638
arg: 'no'
39+
- app-type: jwt-with-mongo-app
40+
arg: 'import-jdl'
41+
- app-type: jwt-with-mongo-cqrs-app
42+
arg: 'import-jdl'
3743
- app-type: jwt-with-postgres-app
3844
arg: 'no'
3945
- app-type: jwt-with-react-app

.github/workflows/test-integration-oauth.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
- oauth-with-angular-cqrs-app
1717
- oauth-with-mssql-app
1818
- oauth-with-mysql-app
19+
- oauth-with-mongo-app
20+
- oauth-with-mongo-cqrs-app
1921
- oauth-with-oracle-app
2022
- oauth-with-postgres-app
2123
- oauth-with-react-app
@@ -29,6 +31,10 @@ jobs:
2931
arg: 'no'
3032
- app-type: oauth-with-mysql-app
3133
arg: 'no'
34+
- app-type: oauth-with-mongo-app
35+
arg: 'no'
36+
- app-type: oauth-with-mongo-cqrs-app
37+
arg: 'no'
3238
- app-type: oauth-with-oracle-app
3339
arg: 'no'
3440
- app-type: oauth-with-postgres-app

docs/Features/cypress.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Cypress
2+
3+
When generating an application, you are able to automatically generate Cypress tests.
4+
5+
## Introduction
6+
7+
Cypress is a next generation front end testing tool built for the modern web. It allows to run multiple end to end tests on all your application features.
8+
9+
## Pre-requisites
10+
11+
When generating your application, make sure to check "Cypress" in your optional testing framworks (by pressing the space bar).
12+
13+
![cypress-choice](../assets/cypress-choice.png)
14+
15+
## How to use it
16+
17+
Once your application is generated, you can optionally add some entities, it will automatically generate the corresponding tests for your entities. To begin, go to your ClientApp folder:
18+
```bash
19+
cd src/YourApplication/ClientApp
20+
```
21+
Then execute one of the following commands:
22+
```bash
23+
npx cypress open
24+
```
25+
or
26+
```bash
27+
./node_modules/.bin/cypress open
28+
```
29+
For futher information you can visit [Cypress wiki](https://docs.cypress.io/guides/guides/command-line#How-to-run-commands).

docs/Features/entity-auditing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class AuditedEntityBase
2020
public DateTime LastModifiedDate { get; set; }
2121
}
2222
```
23-
## Audit of generated Entities
23+
## Audit of generated Entities
2424

2525
For example, if we have a ```Task``` entity and we want to add audit functionality we would inherit from our ```AuditedEntityBase``` like that:
2626
```csharp

docs/Features/mongodb.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# MongoDB
2+
3+
When generating an application, you can choose to use a NoSQL Database thanks to MongoDB.
4+
5+
## Introduction
6+
7+
[MongoDB](https://www.mongodb.com/) is a document-oriented NoSQL database used for high volume data storage. Instead of using tables and rows as in the traditional relational databases, MongoDB makes use of collections and documents.
8+
9+
## Pre-requisites
10+
11+
When generating your application, make sure to choose "MongoDB" as your database.
12+
13+
![mongodb-choice](../assets/mongodb-choice.png)
14+
15+
## Difference with SQL databases
16+
17+
The main difference with the other SQL databases is that your IDs are handled as string and are stored in ObjectID instead of long.
18+
19+
Also, some classes are replaced in order to support MongoDB :
20+
```
21+
BaseEntity => MongoBaseEntity
22+
GenericRepository => MongoGenericRepository
23+
ReadOnlyGenericRepository => MongoReadOnlyGenericRepository
24+
FluentRepository => NoSqlFluentRepository
25+
```
26+
27+
## WIP
28+
29+
Currently, MongoDB is only used for entities. Users/Accounts are managed with a in-memory Sqlite. This feature is still under development.

docs/Features/services.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ Or by using JDL:
1414

1515
Notice that only the service with interface option (serviceImpl) is enabled on this generator.
1616

17-
## Extending and Customizing Services
17+
## Extending and Customizing Services
1818

1919
One common use case is to customize service classes to suit different business needs. When using the jhipster generator to edit an existing entity or upgrading the generator's version, changes to the generated service classes might be overwritten. Altough it is possible to make changes directly to generated service classes, It might get tricky keeping track of changes.
2020

2121
Optionally, you can extend and customize service classes to avoid service class code overwriting.
2222

2323
Example:
24-
Add an Author entity with service generation enabled by using the generator's cli.
24+
Add an Author entity with service generation enabled by using the generator's cli.
2525
Then create the following class named `AuthorExtendedService.cs`:
2626

2727
```csharp
2828
namespace MyCompany.Domain.Services {
29-
public class AuthorExtendedService : AuthorService, IAuthorService
29+
public class AuthorExtendedService : AuthorService, IAuthorService
3030
{
3131
public CountryExtendedService(ApplicationDatabaseContext applicationDatabaseContext) : base(applicationDatabaseContext)
32-
{
32+
{
3333
}
34-
35-
public override async Task Delete(long id)
34+
35+
public override async Task Delete(long id)
3636
{
3737
// add custom business logic before delete
3838
await base.Delete(id);

docs/assets/cypress-choice.png

4.5 KB
Loading

docs/assets/mongodb-choice.png

4.23 KB
Loading

generators/entity-server/templates/dotnetcore/src/Project.Application/Commands/EntityDeleteCommand.cs.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ namespace <%= namespace %>.Application.Commands
2323
{
2424
public class <%= pascalizedEntityClass %>DeleteCommand : IRequest<Unit>
2525
{
26-
public long Id { get; set; }
26+
public <%= primaryKeyType %> Id { get; set; }
2727
}
2828
}

generators/entity-server/templates/dotnetcore/src/Project.Application/Queries/EntityGetAllQueryHandler.cs.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ namespace <%= namespace %>.Application.Queries
5555
public async Task<<%= hasDto ? "Page" : "IPage" %><<%= hasDto ? asDto(pascalizedEntityClass) : pascalizedEntityClass %>>> Handle(<%= pascalizedEntityClass %>GetAllQuery request, CancellationToken cancellationToken)
5656
{
5757
var page = await _<%= camelCasedEntityClass %>Repository.QueryHelper()
58+
<%_ if (databaseType != 'mongodb') { _%>
5859
<%_ relationships.forEach( relationship => {
5960
if (relationship.relationshipType === 'many-to-one' || relationship.relationshipType === 'one-to-one') { _%>
6061
.Include(<%= camelCasedEntityClass %> => <%= camelCasedEntityClass %>.<%= relationship.relationshipFieldNamePascalized %>)
6162
<%_ } else if (relationship.relationshipType === 'many-to-many' && relationship.ownerSide) { _%>
6263
.Include(<%= camelCasedEntityClass %> => <%= camelCasedEntityClass %>.<%= relationship.relationshipFieldNamePascalizedPlural %>)
6364
<%_ }
6465
}); _%>
66+
<%_ } _%>
6567
.GetPageAsync(request.Page);
6668
<%_ if (hasDto) { _%>
6769
return new Page<<%= asDto(pascalizedEntityClass) %>>(page.Content.Select(entity => _mapper.Map<<%= asDto(pascalizedEntityClass) %>>(entity)).ToList(), request.Page, page.TotalElements);

0 commit comments

Comments
 (0)