Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » system facilities » Database
next | previous | forward | backward | up | index | toc

Database -- the class of all database files

Description

A database file is just like a hash table, except both the keys and values have to be strings. In this example we create a database file, store a few entries, remove an entry with remove, close the file, and then remove the file.
i1 : filename = temporaryFileName () | ".dbm"

o1 = /tmp/M2-30740-0/0.dbm
i2 : x = openDatabaseOut filename

o2 = /tmp/M2-30740-0/0.dbm

o2 : Database
i3 : x#"first" = "hi there"

o3 = hi there
i4 : x#"first"

o4 = hi there
i5 : x#"second" = "ho there"

o5 = ho there
i6 : scanKeys(x,print)
second
first
i7 : remove(x,"second")

o7 = ho there
i8 : scanKeys(x,print)
first
i9 : close x

o9 = 0
i10 : removeFile filename

See also

Functions and methods returning a database:

  • openDatabase(String) -- see openDatabase -- open a database file
  • openDatabaseOut(String) -- see openDatabaseOut -- open a database file for writing

Methods that use a database:

  • Database #? String -- see #? -- check existence of value in a list, hash table, database, or string
  • isOpen(Database) -- see isOpen -- whether a file or database is open
  • keys(Database) -- see keys -- keys used in a hash table, dictionary, or database
  • Database # String -- see List # ZZ -- get value from list, hash table, database, dictionary, or string
  • Manipulator Database -- see Manipulator -- the class of all file manipulators
  • remove(Database,String) -- see remove -- remove an entry from a mutable hash table, list, or database
  • scanKeys(Database,Function) -- see scanKeys -- apply a function to each key in a hash table or database

For the programmer

The object Database is a type, with ancestor class Thing.


The source of this document is in Macaulay2Doc/ov_system.m2:1608:0.