您也可以使用 X DevAPI 来操作关系表。在 MySQL 中,每个关系表都关联特定的存储引擎。本节中的示例使用 InnoDB 表,这些表位于 world_x 模式中。You can also use X DevAPI to work with relational tables. In
MySQL, each relational table is associated with a particular
storage engine. The examples in this section use
InnoDB tables in the
world_x schema.
确认模式Confirm the Schema
要显示分配给 db 全局变量的模式,请执行 db。To show the schema that is assigned to the db
global variable, issue db.
mysql-js> db
<Schema:world_x>
如果返回的值不是 Schema:world_x,请按如下方式设置 db 变量:If the returned value is not Schema:world_x,
set the db variable as follows:
mysql-js> \use world_x
Schema `world_x` accessible through db.
显示所有表Show All Tables
要显示 world_x 架构中的所有关系表,请在 db 对象上使用 getTables() 方法。To display all relational tables in the world_x
schema, use the getTables() method on the
db object.
mysql-js> db.getTables()
{
"city": <Table:city>,
"country": <Table:country>,
"countrylanguage": <Table:countrylanguage>
}
基本表操作Basic Table Operations
按表范围的基本操作包括:Basic operations scoped by tables include:
| 操作形式Operation form | 说明Description |
|---|---|
db. |
insert() 方法将一个或多个记录插入指定表中。The insert() method inserts one or more records into the named table. |
db. |
select() 方法返回指定表中的部分或全部记录。The select() method returns some or all records in the named table. |
db. |
update() 方法更新指定表中的记录。The update() method updates records in the named table. |
db. |
delete() 方法从指定表中删除一个或多个记录。The delete() method deletes one or more records from the named table. |
相关信息Related Information
有关更多信息,请参阅 处理关系表。See Working with Relational Tables for more information.
CRUD EBNF 定义 提供了完整的操作列表。CRUD EBNF Definitions provides a complete list of operations.
有关设置
world_x示例架构的说明,请参阅 第 22.3.2 节,“下载和导入 world_x 数据库”。See Section 22.3.2, “Download and Import world_x Database” for instructions on setting up theworld_xschema sample.