Forum > Databases

Collections Persistence to Database Such as MySQL, SQLite

(1/1)

swooper:
I am looking for a library in FreePascal that can help in persisting generics/collections to disk and database.

I currently use this type of collections library in FreeBasic that mimics Java's mdtypes. And the author has created a persistence class that saves the objects onto disk flat file or into MySQL or SQLite. And can be extended to other databases.

https://www.freebasic-portal.de/tutorials/using-mdtypes-en-108.html

It can handle a variety of list and map objects.


--- Quote ---list classes:
- md/util/mdCollection(T)
-- md/util/mdList(T)
---- md/util/mdVector(T)
------ md/util/mdStack(T)
-- md/util/mdSet(T)
-- md/util/mdQueue(T)

map classes:
- md/util/mdMap(K, V) (using inner class mdMapEntry(K, V))
--- md/util/mdDictionary(K, V)
----- md/util/mdHashtable(K, V)
------- md/util/mdProperties

mdTypes comes with another feature, which makes things a lot easier. With the persistence api one can simply save objects and whole collections into different databases.

Currently, mdTypes supports SQLite, MySQL and an own file based format. The classes are called:
- mdSQLitePersistence
- mdMySQLPersistence
- mdTypesPersistence
--- End quote ---

Is there an equivalent library or project that has already been done that can easily "persist" list and map objects easily to disk and database?

Doing some searching the last couple of days, I didn't come across anything similar in terms of simplicity and completeness.

I read this old PDF: https://www.freepascal.org/~michael/articles/persistence2/persistence2.pdf about persistence with InstantObjects. But I'm not sure if this is even around any more.

Any help would be very appreciated. Thanks in advance.

Thaddy:
TiOPF https://sourceforge.net/projects/tiopf/
mORMot https://synopse.info/fossil/wiki?name=SQLite3+Framework

I use both. Both are fully featured and quite popular in our community.

I also use two ways of poor man's Object Persistence:
- Stream in/out the objects to a database through JSON (using packages fcl-json and sqldb).
- Stream in/out the objects derived from Tpersistent using build-in object streaming to a database using just unit classes and sqldb
In the context of OPF there are useful interfaces in classes: IFPObserver and IFPObserved already implemented in TPersistent.
(Definitely implemented for Tstrings, TCollection and TList. Many db objects inherit from those, so can be used immediately.)
Both of these streaming methods can easily be combined with the TDictionary<key,value> from package rtl-generics. (installable for 3.0.4 from the Online Package Manager and default in trunk)

These last two seem close to what you did with FreeBasic. Something like TiOPF or mORMot is much more powerful, but has a learning curve.
I recommend experimenting with all these four options. For all of them there are many examples to be found.

[edit]
I totally forgot about instantObjects: I used it in my Delphi days professionally. Also very usable and Michael is a very good technical writer. Updates were 1 year ago, but it is quite mature. The other two frameworks are more actively maintained.
But I guess my poor man's suggestion is more in line of what you expected from the FreeBasic days.

swooper:
Thank you Thaddy for the links and help. Sorry for the late reply.

I'll be experimenting with the two options you listed:

TiOPF https://sourceforge.net/projects/tiopf/
mORMot https://synopse.info/fossil/wiki?name=SQLite3+Framework

To get a sense of how much learning curve I would need.

It seems that most persistence frameworks involve some type of serialization/de-serialization in a format such as XML or JSON, or a proprietary text format. That's a lot of overhead in some cases, especially for complex dictionary tree structures.

taazz:

--- Quote from: swooper on August 04, 2018, 02:40:53 am ---Thank you Thaddy for the links and help. Sorry for the late reply.

I'll be experimenting with the two options you listed:

TiOPF https://sourceforge.net/projects/tiopf/
mORMot https://synopse.info/fossil/wiki?name=SQLite3+Framework

To get a sense of how much learning curve I would need.

It seems that most persistence frameworks involve some type of serialization/de-serialization

--- End quote ---
yes they do it is the only way to transform the data from the database buffers to internal memory formats (classes,records etc)

--- Quote from: swooper on August 04, 2018, 02:40:53 am ---in a format such as XML or JSON, or a proprietary text format. That's a lot of overhead in some cases, especially for complex dictionary tree structures.

--- End quote ---
no you assume wrong I suggest to take close look at tiopf first you will see that although xml is supported as a target its not always present.

If you want to avoid serialization/deserialization, you could use the sqldb framework and write your own mySQL dataset descendant that uses the mysql buffers directly to store and retrieve data instead of records/classes that should give you some speed up.

Navigation

[0] Message Index

Go to full version