Databases Reference
In-Depth Information
Standards watch: complex APIs can still be portable if they're standardized
and have portability tests
It's important to note that complex interfaces can still permit high portability. For
example, XQuery, a query language used in XML systems, has hundreds of functions,
which can be considered a complex application-database interface. But these func-
tions have been standardized by the World Wide Web (W3C) and are still considered
to be a low-cost and highly portable application-database interface layer. The W3C
provides a comprehensive XQuery test suite to verify if the XQuery interfaces are con-
sistent between implementations. Any XQuery implementation that has over a 99%
pass rate allows applications to be ported without significant change.
4.1.3
Using a key-value store
Let's take a look at how an application developer might use a key-value store within an
application. The best way to think about using a key-value store is to visualize a single
table with two columns. The first column is called the
key
and the second column is
called the
value
. There are three operations performed on a key-value store: put, get,
and delete. These three operations form the basis of how programmers interface with
the key-value store. We call this set of programmer interfaces the
application program
interface
or
API
. The key-value interface is summarized in figure 4.5.
Instead of using a query language, application developers access and manipulate a
key-value store with the
put
,
get
, and
delete
functions, as shown here:
1
put($key as xs:string, $value as item())
adds a new key-value pair to the
table and will update a value if this key is already present.
2
get($key as xs:string) as item()
returns the value for any given key, or it
may return an error message if there's no key in the key-value store.
3
delete($key as xs:string)
removes a key and its value from the table, or it
many return an error message if there's no key in the key-value store.
Inputs
Key
Value
Outputs
1
PUT
123
value123
123
value123
2
GET
456
456
value456
value456
3
DELETE
789
789
Figure 4.5
The key-value store API has three simple commands:
put
,
get
, and
delete
. This diagram shows how the
put
command inserts the input key
"123"
and
value
"value123"
into a new key-value pair; the
get
command presents the key
"456"
and retrieves the value
"value456"
; and the
delete
command presents the
key
"789"
and removes the key-value pair.