No need to pervert the interfaces as much as you propose. Instead, provide new
functions get-database-many and put-database-many that handle multiple this and that.
"William M. Perry" wrote:
"Stephen J. Turnbull" <turnbull(a)sk.tsukuba.ac.jp>
writes:
> >>>>> "-BP" == William M Perry <wmperry(a)aventail.com>
writes:
>
> -BP> To merge the LDAP code, you would have to do a major overhaul
> -BP> of the existing database code, and I'm not sure you would be
> -BP> able to get the full power of LDAP without making the
> -BP> 'normal' databases pretty difficult to use.
>
> OK, that's why it might be hard. It still sounds like it's a good
> idea to me.
Perhaps, but I think that the code to do anything ldap-ish would still look
very ldap-ish as opposed to abstract-database-ish. Another big problem
with LDAP vs. the other database types is the ability to have multiple
values off of a single attribute, and each 'key' in the database can have
multiple attributes. In LDAP you have:
uid=wmperry,ou=aventail.com,c=us -> cn = William M. Perry
Bill Perry
Emacs Dork
mail = wmperry(a)aventail.com
The older database backends would require you to do:
You could theoretically do:
- extend open-database to take a plist, but this breaks all (any?) existing
code. LDAP would be a generic instance with
(open-database '(:host "ldap.in.aventail.com" :type ldap :subtype 3
:bind-username "something"
:bind-password "somethingelse"
:base "o=aventail.com, c=us"))
- extend get-database to be able to return multiple hits for a key.
(get-database KEY ATTRIBUTE DATABASE)
Documentation:
Return value(s) for ATTRIBUTE on object KEY in DATABASE.
An assoc list is returned, the car of each entry in the list the
attribute name. The cdr is a list of values for that attribute.
If there is no corresponding value, return nil.
If ATTRIBUTE is t, returns all attributes and values.
(get-database "uid=wmperry,
o=aventail.com, c=us" "mail" dbhandle)
=> '(("mail" "wmperry(a)aventail.com"))
(get-database "uid=wmperry,
o=aventail.com, c=us" "cn" dbhandle)
=> '(("mail" "wmperry(a)aventail.com")
("cn" "William M. Perry" "Bill Perry" "Emacs
Dork"))
- extend put-database to be able to set multiple hits for a key, and submit
multiple changes at once.
(put-database KEY VALUES DATABASE &optional replace)
Documentation:
Updated record KEY in DATABASE with new VALUES.
VALUES is an assoc list of attribute/value pairs.
Some databases support multiple values.
If optional fourth arg REPLACE is non-nil,
replace any existing entry in the database.
This whole doc string needs better updates. :)
(put-database "uid=wmperry,
o=aventail.com, c=us"
'("cn" "Willie Perry")
dbhandle nil)
=> t
Would _add_ a CN to the record, so we'd now look like:
uid=wmperry,ou=aventail.com,c=us -> cn = William M. Perry
Bill Perry
Emacs Dork
Willie Perry
mail = wmperry(a)aventail.com
- New function search-database
(search-database DATABASE CRITERIA)
Documentation:
Search DATABASE for records matching CRITERIA.
CRITERIA is a property list. It is up to the backend database to convert
this to native representation.
Maybe we could have something for this that looks more lispish than an
LDAP request. I'm not sure how a berkeley db database would implement
this. For LDAP, we could have something like:
(search-database dbhandle
'(& (| ("cn" "William M. Perry" "Bill
Perry"))
("mail" "wmperry(a)aventail.com")))
The ldap backend would convert this into:
"(& (| (cn=William M. Perry") (cn="Bill Perry"))
(mail=wmperry(a)aventail.com"))"
And pass that off to ldap_search()
- map-database would have to be revamped to return new values, etc.
It would be nice if you could register new database backends at runtime,
even for lisp functions. Then you could write an SQL backend in lisp using
<
URL:http://www.chez.com/emarsden/downloads/pg.el>. That could be done by
having a generic 'elisp' backend in database.c, and be able to do something
like:
(define-database TYPE FUNCPLIST)
Where the entries in FUNCPLIST would be the generic name 'open' 'close'
'search' etc would be the key, and the value would be the actual lisp
function to call to do the searching.
That's all just off the top of my head, but it might work. :)
-Bill P.