chain-db-ts
Advanced tools
Changelog
[1.0.0-rc.3] - 2025-03-11
getCurrentDocId()
method.Changelog
[1.0.0-rc.2] - 2025-03-05
TableDoc
interface for working with specific documentsrefetch()
method to TableDoc
to get the latest document datagetTableName()
method to TableDoc
to get the table nameisEmpty()
method to TableDoc
to check if the document is emptyDocId<Model>
type that adds a readonly doc_id
property to modelsgetCurrentDocId()
method to Table
to get the current document IDpersist()
method now returns the created document with its doc_id
doc_id
property in both Table
and TableDoc
instancestable
property to currentDoc
in Table
class for better semanticsDocId<Model>
typeupdate()
method from Table
class
getDoc()
to get a document reference and then call update()
on that referenceBefore:
// Accessing table data
console.log(greetingTable.table)
// Accessing document data from TableDoc
console.log(specificDoc.table)
After:
// Accessing current document data from Table
console.log(greetingTable.currentDoc)
// Accessing document data from TableDoc
console.log(specificDoc.doc)
Before:
// Update the last item
greetingTable.table.greeting = 'Updated greeting'
await greetingTable.update()
// Update a specific document by ID
greetingTable.table.greeting = 'Updated specific document'
await greetingTable.update('550e8400-e29b-41d4-a716-446655440000')
After:
// Get a specific document by ID
const specificDoc = await greetingTable.getDoc('550e8400-e29b-41d4-a716-446655440000')
// Update the document
specificDoc.doc.greeting = 'Updated greeting'
await specificDoc.update()
// Optionally, refetch the document to get the latest data
await specificDoc.refetch()
New in this version:
// When persisting data, you get the document ID in the result
const result = await greetingTable.persist()
console.log(result.doc_id) // The ID of the newly created document
// You can also get the current document ID directly from the table
const currentDocId = greetingTable.getCurrentDocId()
// When working with a specific document, the ID is available in multiple ways
const specificDoc = await greetingTable.getDoc(docId)
console.log(specificDoc.doc_id) // From the TableDoc instance
console.log(specificDoc.doc.doc_id) // From the document object