X DevAPI 中提供下列 SQL CRUD 函數。
Table.insert()
方法的作用類似於 SQL 中的 INSERT
陳述式。它用於將資料儲存在資料庫中的關聯式表格中。它會由 execute()
函數執行。
下列範例示範如何使用 Table.insert() 函數
。此範例假設 test
綱要存在,且已指派給變數 db
,且存在一個名為 my_table
的空表格。
MySQL Shell JavaScript 程式碼
// 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 程式碼
# 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 程式碼
// 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# 程式碼
// 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 程式碼
# 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 程式碼
// 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++ 程式碼
// 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()
傳回的結果。