[ejabberd] mod_archive2 and ejabberd_storage

Alexander Tsvyashchenko lists at ndl.kiev.ua
Mon Jan 11 16:22:24 MSK 2010


Hello All,

Some information regarding new mod_archive2 module for server-side
archiving is posted here:
https://www.ndl.kiev.ua/content/modarchive2-status

I will not repeat it here, but rather concentrate on new storage
implementation used in this module: ejabberd_storage, as it might be
interesting for other module developers.

Basically, ejabberd_storage allows to perform simple database operations
transparently whether it is Mnesia or SQL RDBMS. No "fancy" features are
supported, but all the features that were necessary for mod_archive2
implementation, which is comparably heavy on DB usage (including
offset/limit, sorting, aggregation) are present.

API uses matching expressions, so you can write something along the lines:

ejabberd_storage:transaction(?HOST,
  fun() ->
    ejabberd_storage:select(
      ets:fun2ms(
        fun(#archive_message{body = Body, name = Name})
            when Name =/= "me" ->
          {Body, Name}
        end), [{order_by, {#archive_message.name, asc}}])
      end).

and expect it to work whether underlying DB is Mnesia or SQL-based RDBMS.

Some more examples of supported operations are available in mod_archive2
unit tests (especially
http://github.com/ndl/mod_archive2/blob/master/test/unit/ejabberd_storage_odbc_test.erl
and
http://github.com/ndl/mod_archive2/blob/master/test/unit/ejabberd_storage_test.erl)
and the module code itself.

Matching expressions translation to SQL has a lot of restrictions, but on
practice covers everything I've faced with when developing mod_archive2 and
even more, so should be generally usable for wide range of tasks.

Currently supported RDBMSes are: MySQL, PostgreSQL, sqlite3 and adding new
ones should be quite easy.

There's no documentation available so far except of in-source comments,
but if there's enough interest in that, I can sketch out some API
description document.

Comments are appreciated.

-- 
Good luck!                                     Alexander


More information about the ejabberd mailing list