JDB/Methods/Structural

From J Wiki
Jump to: navigation, search
JDB: Layout Columns | Queries Σ | API: Structural Records | Client/Server | Implementation | Examples

Structural methods are not wrapped in a transaction, and should be called when the database is offline.


Folder

Folder methods are called in the jdb locale. The folder directories themselves should be created or deleted outside of JDB.

Open

Opens a folder, returning locale name. If already open, the existing locale name is returned. The argument is a folder name, for example:

hf=: Open_jdb_ '/home/chris/data'

Close

Closes a folder, and any open content in that folder. The argument is a folder name or locale, or '*' for all folders. For example:

Close_jdb_ hf

Databases List

Contains a boxed list of database names in the folder. For example:

databasesList=: Databases__hf

Database

Database methods are called in the corresponding folder locale.

Create

Creates a database, returning locale name. The argument is a database name, for example:

hd=: Create__hf 'sandp'

Note that with hf defined as above, this creates database:

/home/chris/data/sandp

Drop

Drops a database, and any content in that database. The argument is a database name or locale, for example:

Drop__hf 'sandp'

No error is signalled if the database does not exist.

Open

Opens a database, returning locale name. If already open, the existing locale name is returned. The argument is a database name, for example:

hd=: Open__hf 'sandp'

Close

Closes a database, and any open content in that database. The argument is a database name or locale, or '*' for all databases, for example:

Close__hf 'sandp'

Table

Table methods are called in the corresponding database locale.

Create

Creates a table, returning locale name. The argument is a table name, for example:

ht=: Create__hd 'sp'

Note that with hd defined as above, this creates table:

/home/chris/data/sandp/sp

Create takes additional optional arguments of column names and data. This is equivalent to creating the table, and then calling the corresponding InsertCols and Insert methods:

ht=: Create__hd 'sp';columndefs;data

Drop

Drops a table. The argument is a table name or locale. The table cannot be referenced by another table. For example:

Drop__hd 'sp'

Tables List

Contains a boxed list of table names. For example:

tablesList=: Tables__hd

Column

Column methods are called in the corresponding database locale.

InsertCols

Insert new columns into a table. The argument is a pair:

tablename;text string with one column definition per line, each of the form:

name type [;]

where:

  • name is the column name
  • type is either a datatype, or a referenced table
  • there may be a single semicolon in the definition. If given, all columns before the semicolon must be collectively unique.

For example:

InsertCols__hd 'dept';0 : 0
tno int;
rnum region
tname varchar
tsize varchar
)

defines columns:

  • tno is a unique integer
  • rnum is keyed to table region
  • tname and tsize are varchar fields

DeleteCols

The argument is a pair: tablename;list of column names to delete. The columns cannot be referenced from elsewhere in the database.

ReadCols

Read column definitions as a table of name;value pairs. Verb ShowCols is the same but formats the result with names in columns. The argument is the table name, or '*' for all tables:

   ShowCols__locD 't'
+-----+------+-------+------+------+---------+
|table|column|type   |unique|parent|parentkey|
+-----+------+-------+------+------+---------+
|t    |tno   |int    |1     |      |         |
|t    |enum  |autoid |1     |e     |autoid   |
|t    |tname |char   |1     |      |         |
|t    |tsize |varchar|1     |      |         |
|t    |tcat  |byte   |0     |      |         |
+-----+------+-------+------+------+---------+