← Back to team overview

dubuntu-team team mailing list archive

Re: API and Database specification

 

hi,
i was very busy with some urgent work and, sad to say, spent absolutely
no time on coding. the database description will take a lot of space so
i'll post it in another letter. in this one i'd like to describe the
current state of the api:

== s_db* db_open(void);

opens a connection and populates 's_db' structure. currently it doesn't
accept any arguments. it will accept connection related parameters and a
language identifier that will be used for fetching localized data from
the db.

== bool db_close(s_db* db);

closes a previously open connection and frees memory allocated for s_db
instance. btw the 's_' prefix is part of my naming convention. it allows
me to think less about possible namespace collisions as well as define
variables/fields/etc with more natural names, e.g.:

struct s_book{
  s_text text;
};

i don't insist on using it but in my code you can find it everywhere so
i thought a little explanation would be necessary.

== size_t db_exists(s_db* db, const char* path, bool* is_cat);

checks whether a path exists in the database. the format for path is
this:

path = '/' | ( '/' name ){1,}

examples:
/
/development/desktop
/multimedia/audio/players/realplayer

and this is how the function  works: it creates a sha1 hash from the
path, and fetches a record that matches the hash from a special table
called 'rels' (short for relations). the matched record (if any)
contains a package/category id and a boolean field 'is_cat' telling
whether the record corresponds to a category or package. the parameter
is_cat if not NULL accepts the value of this field and id is returned
from the function.

== s_db_item* db_read(s_db* db, const char* path);

this function just fetches a record from either 'packs' or 'cats' table.
it uses db_exists to obtain an id and populates a s_db_item structure
with information from a corresponding record. s_db_item is used for both
categories and packages. it contains several fields that are common for
packages and categories and a union for those that differ. if this
function succeeds it returns a pointer to a malloced s_db_item instance
that can be destroyed with free.

== bool db_write(s_db* db, const char* path, s_db_item* item);

item is populated by the frontend. the function succeeds only when path
is valid.

== bool db_create(s_db* db, const char* path, s_db_item* item);

adds a record to either 'cats' or 'packs'. s_db_item has a field 'type'
that tells the function which table to use.

== bool db_destroy(s_db* db, const char* path);

removes a record from the db.

== char** db_list(s_db* db, const char* path, bool** cats);

lists all items inside a category. this function fails if path
corresponds to a package. returns a list of null-term. strings. cats if
not NULL contains an array of bools after the function returns.

== bool db_set_language(s_db* db, const char* language);

sets current language.

== bool db_get_language(s_db* db, char* language);

gets current language. language is a five character sequence:

xx-XX

e.g. en-US

== that's it for the moment. i'm gonna add functions for
adding/removing/listing repositories and functions for explicit
pattern-matching.

p.s.
as we haven't come in terms on several quite important subjects yet i
think now we should concentrate on working with packages and package
categories and leave search categories/package groups/etc for future. if
everyone will decide to go his own way then at least we will have some
common codebase that can be used in both our approaches.

jay

On Thu, 2009-07-23 at 21:26 +0200, Charl Wentzel wrote: 
> Hi Jay
> 
> How's your proposal coming?  I'm quite anxious to see it.
> 
> Regards
> Charl
> 
> PS: How did you project (and deadlines) go?
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dubuntu-team
> Post to     : dubuntu-team@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dubuntu-team
> More help   : https://help.launchpad.net/ListHelp




Follow ups

References