Persistent data storage, how?

Hello, how is persistence implemented in a simple way in the Haiku with C++? For example, if I want to write a simple management of customers with their addresses?
Thanks a lot

You could look at how the People app manages contacts using BFS filesystem attributes. This has the benefit of allowing you to create custom queries to search through your contacts.


Thank you very much. Interesting and helpful. The pictures of the contacts are stored in the files and the rest of the information as attributes.

Attributes are useful if you want to use the query support in the filesystem.

If you don’t need that and you just want to store data in files:

  • The entry point is the BFile class, but that is just a way of reading and writing file content, it is quite lowlevel
  • You can use classes implementing “BFlatennable”, which is an API for easily storing some class into a file and reloading it. This only provides the API, and does not give much help on actually saving and loading the data,
  • One readily-available implementation of BFlattenable is BMessage. So you can easily store your data in a BMessage, and then write that to a file,
  • You can use this by filling in the data in the message manually, or you can use classes implementing BArchivable to help structure conversion of your own data structures into BMessage.

This will result in binary files (not plaintext), but they can be explored with the command-line “message” tool or with more advanced editors like Kottan.