Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl egg-bin dal gen #257

Merged
merged 1 commit into from Mar 22, 2024
Merged

feat: impl egg-bin dal gen #257

merged 1 commit into from Mar 22, 2024

Conversation

killagu
Copy link
Contributor

@killagu killagu commented Mar 22, 2024

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Summary by CodeRabbit

  • New Features
    • Introduced a new command for generating data access layer (DAL) code, enhancing the app's data management capabilities.
  • Documentation
    • Updated README with instructions on generating DAL code and added a reference to further documentation.
  • Chores
    • Updated .gitignore to exclude .eslintcache files.
  • Tests
    • Added tests for the new DAL generation functionality.

Copy link

vercel bot commented Mar 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
egg-bin ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2024 3:31pm

Copy link

coderabbitai bot commented Mar 22, 2024

Walkthrough

This update introduces a new feature for generating data access layer (DAL) code, enhancing the @eggjs/tegg-dal-plugin with command-line support. It adds the ability to ignore certain files in version control, updates the documentation, and incorporates testing for the new DAL functionality. The changes streamline the process of generating DAL modules, making it easier for developers to work with database entities.

Changes

Files Change Summaries
.gitignore Added .eslintcache to ignored files
README.md Added instructions for generating DAL code
lib/cmd/dal.js, lib/cmd/dal/gen.js Introduced classes for DAL code generation commands
lib/dal-gen.js Added functionality for generating DAL code
test/.../dal/Bar.ts, test/.../dal/Foo.ts Added classes for database tables
test/lib/cmd/dal.test.js Added tests for DAL functionality file generation

🐰✨📝✨🐰
In the land of code and mist,
A rabbit hopped and gently hissed.
"Let's make DAL gen quick and neat,
With commands and tests, oh what a feat!"
Now with a hop, skip, and a cheer,
Our code's more elegant, have no fear!
🐰✨📝✨🐰

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@killagu
Copy link
Contributor Author

killagu commented Mar 22, 2024

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cff838f and e1ab433.
Files ignored due to path filters (4)
  • package.json is excluded by: !**/*.json
  • test/fixtures/dal/app/modules/dal/package.json is excluded by: !**/*.json
  • test/fixtures/dal/package.json is excluded by: !**/*.json
  • test/fixtures/dal/tsconfig.json is excluded by: !**/*.json
Files selected for processing (8)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • lib/cmd/dal.js (1 hunks)
  • lib/cmd/dal/gen.js (1 hunks)
  • lib/dal-gen.js (1 hunks)
  • test/fixtures/dal/app/modules/dal/Bar.ts (1 hunks)
  • test/fixtures/dal/app/modules/dal/Foo.ts (1 hunks)
  • test/lib/cmd/dal.test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments: 5
test/fixtures/dal/app/modules/dal/Bar.ts (1)
  • 1-19: The class definition and decorators usage are correctly implemented for ORM mapping. Consider adding documentation comments to the class and its fields for better maintainability.
lib/cmd/dal.js (1)
  • 6-17: The DalCommand class is correctly implemented. Consider adding an English description or a comment for the description getter to improve accessibility for non-Chinese speaking developers.
test/fixtures/dal/app/modules/dal/Foo.ts (1)
  • 1-23: The class definition and decorators usage, including the unique index, are correctly implemented. Consider adding documentation comments to the class and its fields for better maintainability.
lib/cmd/dal/gen.js (1)
  • 5-39: The DalGenCommand class is well-implemented. Consider adding more detailed error handling or logging in the run method to improve debugging and maintainability.
lib/dal-gen.js (1)
  • 1-36: The DAL code generation script is correctly implemented. Consider adding comments explaining the choice of exit codes (0 for success, 1 for failure) for clarity and maintainability.

Comment on lines +337 to +345
### dal

Generate code for @eggjs/tegg-dal-plugin

```bash
egg-bin dal gen
```

dal document please read [tegg doc](https://github.com/eggjs/tegg/tree/master/plugin/dal).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new section on the dal command is clear and concise, providing straightforward instructions on how to use the egg-bin dal gen command and where to find further documentation. However, to maintain consistency with the rest of the document, consider starting the description with an uppercase letter and adding a comma after "dal document please read" for better readability.

- dal document please read [tegg doc](https://github.com/eggjs/tegg/tree/master/plugin/dal).
+ Dal document, please read [tegg doc](https://github.com/eggjs/tegg/tree/master/plugin/dal).

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### dal
Generate code for @eggjs/tegg-dal-plugin
```bash
egg-bin dal gen
```
dal document please read [tegg doc](https://github.com/eggjs/tegg/tree/master/plugin/dal).
### dal
Generate code for @eggjs/tegg-dal-plugin
```bash
egg-bin dal gen

Dal document, please read tegg doc.


</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines +7 to +42
describe('test/lib/cmd/dal.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
const cwd = path.join(__dirname, '../../fixtures/dal');

afterEach(mm.restore);

describe('egg-bin dal gen', () => {
after(async () => {
await fs.rm(path.join(cwd, 'app/modules/dal/dal'), {
recursive: true,
});
});

it('egg-bin dal gen should work', async () => {
await coffee.fork(eggBin, [ 'dal', 'gen' ], { cwd })
.debug()
.expect('code', 0)
.end();

for (const file of [
'app/modules/dal/dal/dao/BarDAO.ts',
'app/modules/dal/dal/dao/FooDAO.ts',
'app/modules/dal/dal/dao/base/BaseBarDAO.ts',
'app/modules/dal/dal/dao/base/BaseFooDAO.ts',
'app/modules/dal/dal/extension/BarExtension.ts',
'app/modules/dal/dal/extension/FooExtension.ts',
'app/modules/dal/dal/structure/Bar.json',
'app/modules/dal/dal/structure/Bar.sql',
'app/modules/dal/dal/structure/Foo.json',
'app/modules/dal/dal/structure/Foo.sql',
]) {
assert.ok(fs.stat(path.join(cwd, file)));
}
});
});
});
Copy link

@coderabbitai coderabbitai bot Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite for egg-bin dal gen is well-implemented. However, ensure that the fs.stat promise is properly awaited or handled to accurately test for the existence of generated files.

- assert.ok(fs.stat(path.join(cwd, file)));
+ assert.ok(await fs.stat(path.join(cwd, file)));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
describe('test/lib/cmd/dal.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
const cwd = path.join(__dirname, '../../fixtures/dal');
afterEach(mm.restore);
describe('egg-bin dal gen', () => {
after(async () => {
await fs.rm(path.join(cwd, 'app/modules/dal/dal'), {
recursive: true,
});
});
it('egg-bin dal gen should work', async () => {
await coffee.fork(eggBin, [ 'dal', 'gen' ], { cwd })
.debug()
.expect('code', 0)
.end();
for (const file of [
'app/modules/dal/dal/dao/BarDAO.ts',
'app/modules/dal/dal/dao/FooDAO.ts',
'app/modules/dal/dal/dao/base/BaseBarDAO.ts',
'app/modules/dal/dal/dao/base/BaseFooDAO.ts',
'app/modules/dal/dal/extension/BarExtension.ts',
'app/modules/dal/dal/extension/FooExtension.ts',
'app/modules/dal/dal/structure/Bar.json',
'app/modules/dal/dal/structure/Bar.sql',
'app/modules/dal/dal/structure/Foo.json',
'app/modules/dal/dal/structure/Foo.sql',
]) {
assert.ok(fs.stat(path.join(cwd, file)));
}
});
});
});
describe('test/lib/cmd/dal.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
const cwd = path.join(__dirname, '../../fixtures/dal');
afterEach(mm.restore);
describe('egg-bin dal gen', () => {
after(async () => {
await fs.rm(path.join(cwd, 'app/modules/dal/dal'), {
recursive: true,
});
});
it('egg-bin dal gen should work', async () => {
await coffee.fork(eggBin, [ 'dal', 'gen' ], { cwd })
.debug()
.expect('code', 0)
.end();
for (const file of [
'app/modules/dal/dal/dao/BarDAO.ts',
'app/modules/dal/dal/dao/FooDAO.ts',
'app/modules/dal/dal/dao/base/BaseBarDAO.ts',
'app/modules/dal/dal/dao/base/BaseFooDAO.ts',
'app/modules/dal/dal/extension/BarExtension.ts',
'app/modules/dal/dal/extension/FooExtension.ts',
'app/modules/dal/dal/structure/Bar.json',
'app/modules/dal/dal/structure/Bar.sql',
'app/modules/dal/dal/structure/Foo.json',
'app/modules/dal/dal/structure/Foo.sql',
]) {
assert.ok(await fs.stat(path.join(cwd, file)));
}
});
});
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

厉害了。。。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fengmk2, 谢谢您的认可!如果您有任何问题或需要进一步的帮助,请随时告诉我。 😊

(\__/) 
(•ㅅ•) CodeRabbit is happy!
/   づ

Copy link

codecov bot commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a31f9b4) to head (e1ab433).
Report is 1 commits behind head on 5.x.

Additional details and impacted files
@@            Coverage Diff            @@
##               5.x      #257   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines           93        93           
  Branches        16        16           
=========================================
  Hits            93        93           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@killagu killagu merged commit 7195aef into 5.x Mar 22, 2024
23 of 25 checks passed
@killagu killagu deleted the feat/dalgen branch March 22, 2024 15:46
fengmk2 pushed a commit that referenced this pull request Mar 22, 2024
[skip ci]

## [5.16.0](v5.15.1...v5.16.0) (2024-03-22)

### Features

* impl egg-bin dal gen ([#257](#257)) ([7195aef](7195aef))
fengmk2 pushed a commit that referenced this pull request Mar 22, 2024
[skip ci]

## [5.16.0](v5.15.1...v5.16.0) (2024-03-22)

### Features

* impl egg-bin dal gen ([#257](#257)) ([7195aef](7195aef))
@fengmk2
Copy link
Member

fengmk2 commented Mar 23, 2024

@coderabbitai 提交一个 issue,需要将此功能 pick 到 master 分支

Copy link

coderabbitai bot commented Mar 23, 2024

Tip

For best results, initiate chat on the files or code changes.

@fengmk2, I've submitted the issue as requested. It can be found here: Pick DAL Generation Feature to Master Branch. This issue tracks the request to pick the new DAL generation feature introduced in PR #257 to the master branch.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Create a GitHub issue in the eggjs/egg-bin repository
gh issue create --repo eggjs/egg-bin --title "Pick DAL Generation Feature to Master Branch" --body "This issue tracks the request to pick the new DAL generation feature introduced in PR https://github.com/eggjs/egg-bin/pull/257 to the master branch. The feature enhances the Egg.js framework's data access layer capabilities by automating the generation of DAL code, making development processes more efficient. Picking this feature to the master branch will ensure its availability for broader use."

Length of output: 549

fengmk2 pushed a commit that referenced this pull request Mar 26, 2024
[skip ci]

## [5.16.0](v5.15.1...v5.16.0) (2024-03-26)

### Features

* impl egg-bin dal gen ([#257](#257)) ([7195aef](7195aef))

### Bug Fixes

* move tegg to optional peer deps ([#260](#260)) ([843fcd0](843fcd0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants