// 這會觸發類型檢查錯誤 request("GET", "/invalidRoute"); // Error: Argument of type '"/invalidRoute"' is not assignable to parameter of type 'Route'.
相同的概念也可以來動態生成 SQL 查詢語句,同時確保參數的安全性與類型正確性。
1 2 3 4 5 6 7 8 9 10 11
typeTableName = "users" | "posts" | "comments";
functionselectFromTable(table: TableName, id: number): string { return`SELECT * FROM ${table} WHERE id = ${id}`; }
const query = selectFromTable("users", 1); console.log(query); // SELECT * FROM users WHERE id = 1
// 傳入錯誤的表名時,會被 TypeScript 類型檢查發現 selectFromTable("invalidTable", 1); // Error: Argument of type '"invalidTable"' is not assignable to parameter of type 'TableName'.
// 若單位或屬性錯誤,會觸發類型檢查錯誤 applyStyle("background", 10, "px"); // Error: Argument of type '"background"' is not assignable to parameter of type 'CSSProperty'.
constinvalidHandler: EventHandlerName<"click", "button"> = "buttonOnHoverHandler"; // Error: Type '"buttonOnHoverHandler"' is not assignable to type '"buttonOnClickHandler"'.
Azurite Blob service is starting at http://127.0.0.1:10000 Azurite Queue service is starting at http://127.0.0.1:10001 Azurite Table service is starting at http://127.0.0.1:10002
import azure.functions as func from azure.identity import DefaultAzureCredential from azure.mgmt.compute import ComputeManagementClient import logging, os
except Exception as e: logging.error('異常錯誤: %s', str(e))
異常問題:EnvironmentCredential
1 2 3 4 5 6 7 8 9 10
DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue. ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AzureCliCredential: Azure CLI not found on path AzurePowerShellCredential: PowerShell is not installed AzureDeveloperCliCredential: Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then,once installed, authenticate to your Azure account using 'azd auth login'. To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
這個問題表面上看似由於權限不足引起的,但實際上根本原因是缺乏正確的環境變數配置。 要使 Azure Function 能夠正常運作並獲得所需的權限,我們需要在 Function 的環境設置中正確配置相應的環境變數。 這些環境變數包括關鍵的憑證和授權信息,它們使得 Azure Function 能夠在執行過程中獲取必要的存取權限,從而能夠正常與 Azure 資源進行交互。 如果環境變數配置不當或缺失,Azure Function 將無法獲得所需的授權,從而導致權限不足的錯誤。 確保這些環境變數被正確設置和管理,是解決此類問題的關鍵步驟
-- 創建表 CREATETABLE Users ( Id SERIAL PRIMARY KEY, Username VARCHAR(255) NOTNULL, IsDeleted BOOLEANDEFAULTFALSE );
ALTER SEQUENCE users_id_seq RESTART WITH1000; -- 創建部分索引,只針對 IsDeleted = FALSE 的行 CREATEUNIQUE INDEX unique_active_username ON Users (Username) WHERE IsDeleted =FALSE;
+-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+