X DevAPI 中提供以下 SQL CRUD 函数。
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();
Table.select()
方法的工作原理类似于 SQL 中的 SELECT
语句。请注意,Table.select()
和 collection.find()
使用不同的方法对结果进行排序:Table.select()
使用 orderBy()
方法,类似于 SQL 中的 ORDER BY
关键字,而 sort()
方法用于对 Collection.find()
返回的结果进行排序。