Using the Asterisk Database (AstDB)
Having fun yet? It gets even better!
Asterisk provides a powerful mechanism for storing values called the Asterisk database (AstDB). The AstDB provides a simple way to store data for use within your dialplan.
Tip
For those of you with experience using relational databases such as PostgreSQL or MySQL, the Asterisk database is not a traditional relational database. It is a Berkeley DB Version 1 database. There are several ways to store data from Asterisk in a relational database. Check out Chapter 12 for a more about relational databases.
The Asterisk database stores its data in groupings called families, with values
identified by keys. Within a family, a key may be
used only once. For example, if we had a family called test, we could store only one value with a key
called count. Each stored value must
be associated with a family.
Storing Data in the AstDB
To store a new value in the Asterisk database, we use the
Set()
application,[85] but instead of using it to set a channel variable, we
use it to set an AstDB variable. For example, to assign the count key in the test family with the value of 1, write the following:
exten => 456,1,Set(DB(test/count)=1)
If a key named count already
exists in the test family, its
value will be overwritten with the new value. You can also store
values from the Asterisk command line, by running the command database put family key
value. For our example, you would type database put test count 1.