搜尋套件、儲存庫與 APP 分類

套件詳情v0.22.0

mysql1

一個用於連接和查詢 MySQL 與 MariaDB 資料庫的程式庫。

AndroidiOSmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
493
Pub 分數
160

安裝套件

flutter pub add mysql1

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

mysql1 套件是一個 Dart 庫,可讓 Flutter 應用程式連接並查詢 MySQL 與 MariaDB 資料庫。它提供了一個簡單的 API,用於執行 SQL 陳述式、處理交易以及有效管理資料庫連線。此套件專為跨平台使用而設計,支援 Android、iOS、macOS、Windows 與 Linux,非常適合行動與桌面應用程式的後端整合。該套件積極維護,並基於原生 MySQL 協定建構,確保可靠效能與現代資料庫功能的相容性。

適用情境

  • 將 Flutter 應用連接到 MySQL/MariaDB 資料庫
  • 即時執行動態SQL查詢
  • 管理資料庫事務
  • 為移動應用構建後端服務
  • 與現有的基於 MySQL 的系統整合

主要特色

  • 跨平台支援(Android、iOS、macOS、Windows、Linux)
  • 支援 MySQL 和 MariaDB
  • 高效的連接池
  • 交易管理
  • 非同步/等待相容 API

適合對象

  • 需要資料庫存取的行動和桌面應用程式
  • 使用 MySQL/MariaDB 的後端服務
  • 開發全端 Flutter 應用程式的開發者
  • 與現有 MySQL 基礎設施整合的 Teams

使用建議

  • 需要網絡訪問資料庫伺服器
  • 需要對連接問題進行適當的錯誤處理
  • 可能需要為 SSL/TLS 進行額外設定
  • 不適用於基於本機檔案的資料庫

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

mysql1

A MySQL driver for the Dart programming language. Works on Flutter and on the server.

This library aims to provide an easy to use interface to MySQL. mysql1 originated as a fork of the SQLJocky driver.

Usage

Connect to the database

var settings = new ConnectionSettings(
  host: 'localhost', 
  port: 3306,
  user: 'bob',
  password: 'wibble',
  db: 'mydb'
);
var conn = await MySqlConnection.connect(settings);

Execute a query with parameters:

var userId = 1;
var results = await conn.query('select name, email from users where id = ?', [userId]);

Use the results:

for (var row in results) {
  print('Name: ${row[0]}, email: ${row[1]}');
});

Insert some data

var result = await conn.query('insert into users (name, email, age) values (?, ?, ?)', ['Bob', 'bob@bob.com', 25]);

An insert query's results will be empty, but will have an id if there was an auto-increment column in the table:

print("New user's id: ${result.insertId}");

Execute a query with multiple sets of parameters:

var results = await query.queryMulti(
    'insert into users (name, email, age) values (?, ?, ?)',
    [['Bob', 'bob@bob.com', 25],
    ['Bill', 'bill@bill.com', 26],
    ['Joe', 'joe@joe.com', 37]]);

Update some data:

await conn.query(
    'update users set age=? where name=?',
    [26, 'Bob']);

Parameters

Parameters are bound client side. The values are escaped, written into the statement as literals, and the result is sent as a single query - there is no server side prepare/execute/close. This is what mysqlclient does, and so how most MySQL deployments already send their statements.

The reason to do it this way is query planning. A bound value is opaque to the optimizer, so if the leading column of an index is a parameter it takes ref access on that column and never builds a range, and a keyset page can degrade into a scan.

? placeholders inside string literals and inside ` quoted identifiers are left alone. null, int, double, bool, String and DateTime (UTC only, second precision) can be bound, as can Blob and List<int> - both are written as hex literals, so bytes which are not valid in the connection charset survive. Anything else is bound as its toString().

Escaping assumes the connection charset is utf8 or utf8mb4, and that the server is not in NO_BACKSLASH_ESCAPES mode. Both hold for a connection opened by this driver with default settings.

Flutter Web

This package opens a socket to the database. The web platform does not support sockets and so this package does not work on flutter web.

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案