文件首頁
X DevAPI 使用者指南
下載本手冊

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 程式碼

// 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();

圖 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.