# Difference between revisions of "Metakit"

Developer(s) Jean-Claude Wippler {{#property:P1324}} Кроссплатформенная Development Library MIT License[1] www.equi4.com/metakit/

Metakit is an efficient embedded database library with a small footprint. It fills the gap between flat-file, relational, object-oriented, and tree-structured databases, supporting relational joins, serialization, nested structures, and instant schema evolution. There is a C++ API, a Python binding called Mk4py, and a Tcl binding called Mk4tcl. You can manipulate and exchange data between any of these.

Data files are portable. The library has been used on Unix, Windows, Macintosh, VMS, and others, spanning a range of 16- to 64-bit architectures, from PDA's to S390's.

Metakit is in use in various commercial projects and products on millions of desktops.

## General

MetaKit is a freely available, cross platform, open source (MIT-style licensed) database library that you can include in your own programs. It has been developed by Jean-Claude Wippler, the man behind Equi4 Software. MetaKit comes with an API for C++, one for Python, and an API for Tcl called "Mk4tcl".

Like every other database or storage library, MetaKit helps you manage the data you want to store on disk. However, it does things somewhat differently from many other database libraries, which give it a number of unique advantages, some of which are ideally paired to scripting languages like Tcl.

• Both the code and datafiles are portable. All byte-ordering managed by the library.
• Store multiple nested data structures, to create document-centric applications.
• You'll have to see this to believe it: restructure files on-the-fly, while open.
• Complementing commit/rollback of changes, data can also be serialized.
• The use of Stable Storage ensures that files cannot be corrupted by crashes.
• Files are opened without reading data. Memory-mapped files if O/S supports it.
• The API mimics container classes. Quickly get sizes and iterate over rows.
• Sorting, relational join / group by, set operations, permutations, hashing.
• The largest int defines storage format. String/binary data is stored as var-sized.
• Can be linked shared or statically, for hassle-free deployment of components.
• The library is extremely small, unused functions are stripped off in static links.
• Only a small interface is exposed. One header file lists all the classes you need.
• Use from Python and Tcl

## MetaKit Concepts

There are only a few concepts that you'll need to know to use MetaKit. Most of these should be familiar to you if you've used any other database or storage mechanism, though perhaps under a different name.

### Datafile

MetaKit stores all its data in one or more self-contained data files on disk. These live like any other file in the file system; you open them with MetaKit when you want to access your data, and you close them afterwards. When you open a file, you specify a 'tag' that is associated with the open file. You can have multiple data files open at once, where each would have a different tag.

### View

Views let you partition your data files into one or more separate areas, each of which may hold different types of data. The description of what data each view can hold is referred to as its layout, or structure. Views are specified as tag.viewname. Views are equivalent to 'tables' in many other databases.

### Row

A row holds a collection of data related to the same object, such as the name, address, etc. of a person in an address book. This is commonly referred to as a 'record' in many other databases. A view is actually made up of an array of rows, which are referred to by a zero-based index (i.e. the first row is '0', the second is '1', etc.). You can refer to an individual row within a view by tag.viewname!index.

### Properties

A property is an individual data item. Each row will hold one or more properties. Each row within a single view will contain the same properties, though of course they will likely have different values. So for example, every row within the view may have a name and address property, but the values will be different for each row. Rows are commonly known as 'fields' in many other databases. Note that properties are not referred to directly by a notation like for views and rows, but accessed through MetaKit commands like mk::get and mk::set.

## Example

# load MetaKit into our application; Mk4tcl is the name of the Tcl extension
package require Mk4tcl

# open a datafile named mydata.db; we'll refer to it with the tag 'db'
mk::file open db mydata.db

# create a view within the datafile which describes what we'll store
set view [mk::view layout db.addressbook "name country"]

# create a bunch of new rows in the view to store our data
mk::row append $view name "Mark Roseman" country "Canada" mk::row append$view name "Jean-Claude Wippler" country "The Netherlands"
mk::row append $view name "Jeff Hobbs" country "Canada" mk::file commit$view

# search for all living in Canada and print their names
foreach row [mk::select $view country "Canada"] { puts [mk::get$view!\$row name]
}

# close the datafile
mk::file close db

## References

Cite error: Invalid <references> tag; parameter "group" is allowed only.

Use <references />, or <references group="..." />