db_client 0.1.0
db_client: ^0.1.0 copied to clipboard
A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.
db_client #
A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.
This package is a fork of dart_odbc.
Quick Start #
1. Configure the connection #
Create a .env file with your credentials:
SERVER=localhost
DATABASE=your_database
USERNAME=username
PASSWORD=password
DRIVER=ODBC Driver 17 for SQL Server
2. Create a repository #
Use DbClientConfig and SqlDbClient to define your connection:
final config = DbClientConfig(
server: 'localhost',
database: 'your_database',
username: 'username',
password: 'password',
driver: 'ODBC Driver 17 for SQL Server',
);
final client = SqlDbClient(config);
3. Execute queries #
final response = await client.send(
DbRequest.query('SELECT DB_NAME() AS database_name'),
);
if (response.success) {
final result = response.firstOrNull;
print(result);
}
4. Use parameterized queries #
To prevent SQL injection, use parameters:
await client.send(
DbRequest.query(
'SELECT * FROM USERS WHERE UID = ?',
params: [1],
),
);
5. Disconnect #
await client.disconnect();
Features #
- Easy connection: Configure credentials once
- Parameterized queries: SQL injection prevention
- Clean abstraction: Simple API with
DbClientandDbRequest - Error handling: Structured responses with success status
Supported Databases #
- Microsoft SQL Server
- Oracle
- Any database with an available ODBC driver
For more information about ODBC, check the official Microsoft documentation