Skip to content

Database

BastouP411 edited this page Feb 11, 2021 · 6 revisions

This peripheral allows the user to use a SQL database. basic SQL, prepared requests and diverse helpers may be used.

A Database Disk must be inserted inide the databse to function. Every disk holds a separate database and keeps it when transfered to another Database peripheral.

Note: The helpers are a WIP feature so they are not documented yet, even if they are present ingame.

Crafting

Database

To be crafted, the Database requires:

  • 6 stone blocks
  • 1 redstone
  • 1 iron ingot
  • 1 disk drive

Shaped crafting recipe

Database Disk

To be crafted, the Database Disk requires:

  • 1 redstone
  • 3 iron ingots
  • 1 disk

Shaped crafting recipe

Methods

The wraped peripheral will be named database

database.idDiskInserted(): boolean

This checks if Database Disk is inserted inside the Database

database.getDatabaseId(): string

This gets the database id for this disk.

Throws an error if no disk is inserted.

database.getDatabaseName(): string

This gets the database name or nil if no name was set for this disk.

Throws an error if no disk is inserted.

database.setDatabaseName(name: string): string

This sets the database name for this disk.

Throws an error if no disk is inserted.

database.executeSQL(sql: string): table

This executes the provided sql string on the database, and returns a result structure.

Throws an error if no disk is inserted or if there was a problem with the SQL.

database.prepareStatement(sql: string): table

This prepares the provided sql request for the database, and returns a prepared statement.

Result Structure

This structure is returned by every call to the database.

Parameters:

  1. type: string This is the type of the result. May be "update", "query", or "error"
  2. data: number / table / string the data associated with this response. I repesents the number of updated entries if type = "update", the returned table if type = "query", and a summary od the error if type = "error".

Prepared Statement Structure

This structure is returned by the prepareStatement method.

Methods

The structure will be named statement

statement.setParameter(index: number, value: any): table

This sets the parameter at index in the Prepared Statement to value, and returns the Prepared Statement.

statement.removeParameter(index: number): table

This removes the parameter at index in the Prepared Statement, and returns the Prepared Statement.

statement.execute(index: number, value: any): table

This executes the Prepared Statement, and returns a Result structure.

Throws an error if no disk is inserted or if there was a problem with the SQL.

Events

database_attached

database_detached

Clone this wiki locally