Flutter SDK

Flutter / Dart SDK Quick Start — WoWSQL Docs

Flutter / Dart Quick Start

WoWSQL Flutter SDK — Get started in minutes

Get your API key: Use the WoWSQL project dashboard to create or copy your API key. The same key works for database, auth, and storage (unified API key).

Installation

Official package: View on pub.dev →

dart pub add wowsql

Initialize Client

import 'package:wowsql/wowsql.dart';

void main() async {
  // Initialize client with your API key (same key for database, auth, storage)
  final client = WowSQLClient(
    projectUrl: 'myproject',
    apiKey: 'your_api_key_here',
  );

  // Or with full URL
  final clientFull = WowSQLClient(
    projectUrl: 'https://myproject.wowsql.com',
    apiKey: 'your_api_key',
  );

  // Always use select() before get()/execute()
  final users = await client.table('users').select('*').get();
  for (final user in users.data) {
    print(user['name']);
  }
}

Query Data

Basic Queries

// Get all records
final users = await client.table('users').select('*').get();

// With filters
final adults = await client.table('users').select('*').gte('age', 18).get();

// Select specific columns
final names = await client.table('users').select('id', 'name').get();

Advanced Queries

// Multiple filters with sorting
final activeUsers = await client.table('users')
    .select('*')
    .eq('status', 'active')
    .gt('age', 18)
    .order('created_at', 'desc')
    .limit(20)
    .offset(0)
    .get();

print('Found ${activeUsers.count} users');
for (final user in activeUsers.data) {
  print(user['name']);
}

Filter Helper Methods

// Using helper methods: eq, gt, like, in, between
final users = await client.table('users')
    .eq('status', 'active')
    .gt('age', 18)
    .like('email', '%@gmail.com')
    .in_('role', ['admin', 'moderator'])
    .between('created_at', '2024-01-01', '2024-12-31')
    .get();

GROUP BY and Aggregates

Basic GROUP BY

final result = await client.table('products')
    .select('category', 'COUNT(*) as count', 'AVG(price) as avg_price')
    .groupBy('category')
    .get();

final result2 = await client.table('orders')
    .select('DATE(created_at) as date', 'COUNT(*) as orders', 'SUM(total) as revenue')
    .groupBy('DATE(created_at)')
    .orderBy('date', 'desc')
    .get();

HAVING Clause

final result = await client.table('products')
    .select('category', 'COUNT(*) as count')
    .groupBy('category')
    .having('COUNT(*)', 'gt', 10)
    .get();

Multiple ORDER BY

final result = await client.table('products')
    .select('*')
    .orderByMultiple([
      OrderByItem(column: 'category', direction: SortDirection.asc),
      OrderByItem(column: 'price', direction: SortDirection.desc),
    ])
    .get();

CRUD Operations

Create Record

final result = await client.table('users').create({
  'name': 'John Doe',
  'email': 'john@example.com',
  'age': 30,
});
print('Created user with ID: ${result['id']}');

Update Record

await client.table('users').update(123, {'email': 'newemail@example.com'});
print('User updated successfully');

Delete Record

await client.table('users').delete(123);
print('User deleted successfully');

Get Single Record by ID

final user = await client.table('users').getById(123);
print('User: ${user['name']}');

Get First Record

final user = await client.table('users').eq('status', 'active').first();
if (user != null) {
  print('First active user: ${user['name']}');
}

Filter Operators

Available operators: eq, neq, gt, gte, lt, lte, like, is, in, not_in, between, not_between. Use .eq('col', value), .filter('col', 'op', value), etc.

Error Handling

try {
  final users = await client.table('users').select('*').get();
  print('Success: ${users.data.length} users');
} on WowSQLException catch (e) {
  if (e.statusCode == 401) print('Authentication failed — check your API key');
  else if (e.statusCode == 404) print('Table or resource not found');
  else print('Error (${e.statusCode}): ${e.message}');
}

Authentication

Use the same API key for authentication. One key works for database and auth.

Sign Up & Sign In

final auth = WowSQLAuth(projectUrl: 'myproject', apiKey: 'your_api_key');

final result = await auth.signUp(
  email: 'user@example.com',
  password: 'SecurePassword123',
  fullName: 'John Doe',
);
print('Access token: ${result['access_token']}');

final login = await auth.signIn(
  email: 'user@example.com',
  password: 'SecurePassword123',
);
print('User ID: ${login['user']['id']}');

Password Reset

await auth.forgotPassword(email: 'user@example.com');
await auth.resetPassword(token: 'reset_token_from_email', newPassword: 'NewSecurePassword123');

OTP Authentication

await auth.sendOtp(email: 'user@example.com', purpose: 'login');
final result = await auth.verifyOtp(
  email: 'user@example.com',
  otp: '123456',
  purpose: 'login',
);
print('Logged in: ${result.user.id}');

Magic Link & Email Verification

await auth.sendMagicLink(email: 'user@example.com', purpose: 'login');
await auth.verifyEmail(token: 'verification_token_from_email');
await auth.resendVerification(email: 'user@example.com');

OAuth Authentication

final oauthUrl = await auth.getOAuthAuthorizationUrl(
  provider: 'github',
  redirectUri: 'http://localhost:5000/auth/callback',
);
// Redirect user to oauthUrl.authorizationUrl
final result = await auth.exchangeOAuthCallback(
  provider: 'github',
  code: 'authorization_code_from_callback',
);
print('OAuth login successful: ${result.user.id}');

Storage Operations

Initialize Storage

final storage = WowSQLStorage(
  projectSlug: 'myproject',
  apiKey: 'your_api_key',
  baseUrl: 'https://api.wowsql.com',  // optional
);

File Operations

// Upload file from path
final result = await storage.uploadFromPath('path/to/document.pdf', 'uploads/document.pdf', folder: 'documents');
print('Uploaded: ${result["file_key"]}');

// Upload from bytes
import 'dart:typed_data';
final bytes = Uint8List.fromList('Hello, WoWSQL!'.codeUnits);
final upload = await storage.upload(bytes, 'hello.txt', folder: 'uploads', contentType: 'text/plain');
print('Uploaded: ${upload.key}');

// Get file URL with full metadata
final urlData = await storage.getFileUrl('uploads/document.pdf', expiresIn: Duration(hours: 1));
print('File URL: ${urlData["file_url"]}');
print('Bucket: ${urlData["bucket_name"]}');
print('Expires at: ${urlData["expires_at"]}');

// Get presigned URL (simple)
final downloadUrl = await storage.getPresignedUrl('uploads/document.pdf', expiresIn: Duration(hours: 1));
final uploadUrl = await storage.getPresignedUrl('uploads/new-file.pdf', expiresIn: Duration(hours: 1), operation: 'put_object');

// List files
final files = await storage.listFiles(prefix: 'uploads/', maxKeys: 100);
for (final file in files) {
  print('${file.key}: ${file.size} bytes');
}

// Delete file
await storage.deleteFile('uploads/document.pdf');

// Check quota
final quota = await storage.getQuota();
print('Used: ${quota.storageUsedGb.toStringAsFixed(2)} GB');
print('Total: ${quota.storageQuotaGb.toStringAsFixed(2)} GB');
print('Usage: ${quota.usagePercentage.toStringAsFixed(1)}%');

Download or View File

Via REST: use GET .../files/{file_key}/download for attachment download, or GET .../files/{file_key}/view to view inline in the browser.