themetalfleece / neogma

Object-Graph-Mapping neo4j framework, Fully-typed with TypeScript, for easy and flexible node and relationship operations
https://themetalfleece.github.io/neogma/
MIT License
122 stars 12 forks source link

Type converting #58

Closed maroochee closed 1 year ago

maroochee commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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