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

Type converting #58

Closed
maroochee opened this issue May 11, 2023 · 2 comments · Fixed by #63
Closed

Type converting #58

maroochee opened this issue May 11, 2023 · 2 comments · Fixed by #63
Labels
feature New feature or request

Comments

@maroochee
Copy link

maroochee commented May 11, 2023

Hi, I'm starting to use neogma in my project and found out that the return value of .findMany() and QueryBuilder() seems to be different.

QueryRunner.getResultProperties is extracting the properties only

.run(neogma.queryRunner)
.then<SuccessResult<ProjectsInstance[]>>((result) => {
  return {
    type: Result.SUCCESS,
    data: QueryRunner.getResultProperties<ProjectsInstance>(result, 'project'),
  };
})

but findMany() only returns the whole instance

return await Projects.findMany({
    where: {
    },
    order: [['projectID', 'ASC'], ['projectDescription', 'ASC']],
    throwIfNoneFound: true,
    session: null,
}).then<SuccessResult<ProjectsInstance[]>>((result) => {
  return {
    type: Result.SUCCESS,
    data: result
  };
})
.catch((error) => ({
  type: Result.ERROR,
  message: error.message,
  error,
}));

is there any way to convert instance into properties only? or do it by myself?
that instance has "dataValues" property so I need that data only.

[
  {
    "labels": [
      "Project"
    ],
    "__existsInDatabase": true,
    "dataValues": {
      "projectID": "prj-003",
      "projectDescription": "CCC project",
      "createdBy": "001",
      "createdOn": "1996-08-16 00:00:00.000"
    },
    "changed": {
      "projectID": false,
      "projectDescription": false,
      "createdBy": false,
      "createdOn": false
    }
  },
]
@themetalfleece themetalfleece added the feature New feature or request label May 12, 2023
@themetalfleece
Copy link
Owner

Hey, thanks for using neogma :)

Currently there is no way to support it, and you'll have to do a map to get only the dataValues.

However, some ORMs like sequelize have an option to get only the data itself, which is something I can look at :)

themetalfleece added a commit that referenced this issue May 27, 2023
Closes #58.

- Add `plain` param to `findOne` and `findMany` to return the plain
properties.
@themetalfleece
Copy link
Owner

themetalfleece commented May 27, 2023

Released in v1.12.0. You can just pass a plain: true param to findMany and findOne and it should work as you described.

Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants