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

Add firestore timestamps to entities #317

Open
gelouko opened this issue Dec 17, 2022 · 1 comment
Open

Add firestore timestamps to entities #317

gelouko opened this issue Dec 17, 2022 · 1 comment

Comments

@gelouko
Copy link

gelouko commented Dec 17, 2022

When using the firestore admin sdk, we can retrieve the timestamps (createTime, updateTime, readTime) of a document.
This can be helpful when we are using firestore for backend applications and don't want to manually create timestamps

Documentation: https://firebase.google.com/docs/reference/functions/test/test.firestore.DocumentSnapshotOptions


Proposal - Include the types to the entity IF a property with the same name does not exist (user could override this value):

Usage:

import { Collection, getRepository } from 'fireorm';

@Collection()
class Todo {
  id: string;
  text: string;
  done: Boolean;
}

const todoRepository = getRepository(Todo);

const todo = new Todo();
todo.text = "Check fireorm's Github Repository";
todo.done = false;

const todoDocument = await todoRepository.create(todo); // Create todo

const mySuperTodoDocument = await todoRepository.findById(todoDocument.id); // Read todo. Also retrieves createTime, updateTime and readTime from the firestore DocumentRef

mySuperTodoDocument.createTime // 2022-12-17 00:00:00
mySuperTodoDocument.updateTime // 2022-12-17 00:00:00
mySuperTodoDocument.readTime // 2022-12-17 00:00:01

For typescript, we can add a Timestamped wrapper to add some typing to the entity, so anyone could use it as:

export type Timestamped<T> = T & {
  createTime: Date,
  updateTime: Date,
  readTime: Date,
}

Does it make sense?

@gelouko
Copy link
Author

gelouko commented Dec 17, 2022

Oh, just took a look at the PRs and looks like the repo is not maintained anymore :(

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

No branches or pull requests

1 participant