4strid / nekodb

Tiny ODM for MongoDB/NeDB
MIT License
21 stars 5 forks source link

How to set a updateAt time ? #56

Open suoc opened 5 years ago

suoc commented 5 years ago

Nedb's timestampData option can auto set updateAt and createdAt.

How nekodb to set this.

4strid commented 5 years ago

There was no way to pass additional config to the collections automatically created by Neko, I'm putting some in now. The API will be

ko.Model('Timestamped', {
  schema: ko.String,
  etc: ko.String,
}, {
  // new third parameter is collection config
  // here you can pass all the options available in the nedb API, for instance
  timestampData: true
})
4strid commented 5 years ago

Ok as of nekodb version 2.4.0 you should be able to pass in timestampData option to NeDB. Let me know how it goes

suoc commented 5 years ago
const DicomInfo = ko.Model('DicomInfo', {
    PatientID: ko.String.default(''),
    PatientName: ko.Document({ Alphabetic: ko.String.default('') }),
    PatientSex: ko.String.default(''),
    PatientAge: ko.String.default(''),
    Modality: ko.String.default(''),
    BodyPartExamined: ko.String.default(''),
    AccessionNumber: ko.String.default(''),
    TransferSyntaxUID: ko.String.default(''),
    StudyInstanceUID: ko.String.default(''),
    SeriesInstanceUID: ko.String.default(''),
    SeriesNumber: ko.Option([ko.String,ko.Number]),
    SeriesDescription: ko.String.default(''),
    SOPInstanceUID: ko.String.default(''),
    InstanceNumber: ko.Option([ko.String,ko.Number]),
    StudyDate: ko.String.default(''),
    StudyTime: ko.String.default(''),
    StudyDatetime: ko.String.default(''),
    filePath: ko.String.default('')
  }, {
    // new third parameter is collection config
    // here you can pass all the options available in the nedb API, for instance
    timestampData: true
  });

[2019-10-08 09:25:26.510] [DEBUG] [dimse\index.js:95] [default] - saved doc: Instance { _id: [Getter/Setter], PatientID: [Getter/Setter], PatientName: [Getter/Setter], PatientSex: [Getter/Setter], PatientAge: [Getter/Setter], Modality: [Getter/Setter], BodyPartExamined: [Getter/Setter], AccessionNumber: [Getter/Setter], TransferSyntaxUID: [Getter/Setter], StudyInstanceUID: [Getter/Setter], SeriesInstanceUID: [Getter/Setter], SeriesNumber: [Getter/Setter], SeriesDescription: [Getter/Setter], SOPInstanceUID: [Getter/Setter], StudyDatetime: [Getter/Setter], filePath: [Getter/Setter] }

Not effective... There is not timesstamp properties.

suoc commented 5 years ago

Is there a way to got a saved object instead of model.

4strid commented 5 years ago

Ok I doubted myself, but they are in fact being saved to the database they're just not accessible via the model. All you have to do is add

   createdAt: ko.Date.optional(),
   updatedAt: ko.Date.optional(),

to the model and you will have the timestamps.

4strid commented 5 years ago

You can do model.slice() to convert the object to a plain object, but it's still only going to have the fields the model knows about.

suoc commented 5 years ago

Thank you! That's ok for me.