文档主页
X DevAPI 用户指南
下载本手册
PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb


X DevAPI 用户指南  /  使用关系表  /  SQL CRUD 函数语法

6.1 SQL CRUD 函数语法

X DevAPI 中提供以下 SQL CRUD 函数。

Table.insert()

Table.insert() 方法的工作原理类似于 SQL 中的 INSERT 语句。它用于在数据库的关系表中存储数据。它由 execute() 函数执行。

以下示例展示了如何使用 Table.insert() 函数。该示例假设 test 模式存在并且分配给了变量 db,并且存在一个名为 my_table 的空表。

MySQL Shell JavaScript 代码

Press CTRL+C to copy
// Accessing an existing table var myTable = db.getTable('my_table'); // Insert a row of data. myTable.insert(['id', 'name']). values(1, 'Imani'). values(2, 'Adam'). execute();

MySQL Shell Python 代码

Press CTRL+C to copy
# Accessing an existing table myTable = db.get_table('my_table') # Insert a row of data. myTable.insert(['id', 'name']).values(1, 'Imani').values(2, 'Adam').execute()

Node.js JavaScript 代码

Press CTRL+C to copy
// Accessing an existing table var myTable = db.getTable('my_table'); // Insert a row of data. myTable.insert(['id', 'name']). values(1, 'Imani'). values(2, 'Adam'). execute();

C# 代码

Press CTRL+C to copy
// Assumptions: test schema assigned to db, empty my_table table exists // Accessing an existing table var myTable = db.GetTable("my_table"); // Insert a row of data. myTable.Insert("id", "name") .Values(1, "Imani") .Values(2, "Adam") .Execute();

Python 代码

Press CTRL+C to copy
# Accessing an existing table my_table = db.get_table('my_table') # Insert a row of data. my_table.insert(['id', 'name']).values(1, 'Imani').values(2, 'Adam').execute()

Java 代码

Press CTRL+C to copy
// Accessing an existing table Table myTable = db.getTable("my_table"); // Insert a row of data. myTable.insert("id", "name") .values(1, "Imani") .values(2, "Adam") .execute();

C++ 代码

Press CTRL+C to copy
// Accessing an existing table var myTable = db.getTable("my_table"); // Insert a row of data. myTable.insert("id", "name") .values(1, "Imani") .values(2, "Adam") .execute();

图 6.1 Table.insert() 语法图

Content is described in the surrounding text.

Table.select()

Table.select() 方法的工作原理类似于 SQL 中的 SELECT 语句。请注意,Table.select()collection.find() 使用不同的方法对结果进行排序:Table.select() 使用 orderBy() 方法,类似于 SQL 中的 ORDER BY 关键字,而 sort() 方法用于对 Collection.find() 返回的结果进行排序。

图 6.2 Table.select() 语法图

Content is described in the surrounding text.

Table.update()

Table.update() 方法的工作原理类似于 SQL 中的 UPDATE 语句。

图 6.3 Table.update() 语法图

Content is described in the surrounding text.

Table.delete()

Table.delete() 方法的工作原理类似于 SQL 中的 DELETE 语句。

图 6.4 Table.delete() 语法图

Content is described in the surrounding text.