### MySQL Quick Start Source: https://github.com/calsranna/laconic/blob/main/README.md Example of initializing Laconic with MySQL driver and performing a basic query. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_mysql/laconic_mysql.dart'; void main() async { final laconic = Laconic(MysqlDriver(MysqlConfig( host: '127.0.0.1', port: 3306, database: 'my_database', username: 'root', password: 'password', ))); final users = await laconic.table('users').get(); await laconic.close(); } ``` -------------------------------- ### Bash Installation Source: https://github.com/calsranna/laconic/blob/main/README.md Run dart pub get after updating your pubspec.yaml. ```bash dart pub get ``` -------------------------------- ### PostgreSQL Quick Start Source: https://github.com/calsranna/laconic/blob/main/README.md Example of initializing Laconic with PostgreSQL driver and performing a basic query. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_postgresql/laconic_postgresql.dart'; void main() async { final laconic = Laconic(PostgresqlDriver(PostgresqlConfig( host: '127.0.0.1', port: 5432, database: 'my_database', username: 'postgres', password: 'password', ))); final users = await laconic.table('users').get(); await laconic.close(); } ``` -------------------------------- ### SQLite Quick Start Source: https://github.com/calsranna/laconic/blob/main/README.md Example of initializing Laconic with SQLite driver and performing a basic query. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_sqlite/laconic_sqlite.dart'; void main() async { final laconic = Laconic(SqliteDriver(SqliteConfig('app.db'))); // Query users final users = await laconic.table('users').where('active', true).get(); // Don't forget to close await laconic.close(); } ``` -------------------------------- ### Run Example Command Source: https://github.com/calsranna/laconic/blob/main/CLAUDE.md Bash command to run the example application. ```bash dart run example/laconic_example.dart ``` -------------------------------- ### Get all records Source: https://github.com/calsranna/laconic/blob/main/README.md Example of retrieving all records from a table. ```dart final users = await laconic.table('users').get(); ``` -------------------------------- ### Pagination - Laravel Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of pagination in Laravel. ```php $users = DB::table('users') ->orderBy('name') ->paginate(15); ``` -------------------------------- ### Pagination - Laconic Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of manual pagination implementation in Laconic, as native support is missing. ```dart // ❌ 不支持paginate,需要手动实现 final users = await laconic .table('users') .orderBy('name') .limit(15) .offset((page - 1) * 15) .get(); final total = await laconic.table('users').count(); ``` -------------------------------- ### Installation Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_postgresql/README.md Add laconic and laconic_postgresql to your pubspec.yaml file. ```yaml dependencies: laconic: ^2.2.0 laconic_postgresql: ^1.2.0 ``` -------------------------------- ### Get first record Source: https://github.com/calsranna/laconic/blob/main/README.md Example of retrieving the first record from a table. Throws if none found. ```dart final user = await laconic.table('users').first(); ``` -------------------------------- ### Basic Query - Laravel Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of a basic query in Laravel. ```php $users = DB::table('users') ->where('age', '>', 18) ->whereIn('status', ['active', 'pending']) ->orderBy('created_at', 'desc') ->limit(10) ->get(); ``` -------------------------------- ### Get sole record Source: https://github.com/calsranna/laconic/blob/main/README.md Example of retrieving a single record. Throws if none or multiple found. ```dart final user = await laconic.table('users').where('email', 'john@example.com').sole(); ``` -------------------------------- ### Installation Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_mysql/README.md Add laconic and laconic_mysql to your pubspec.yaml dependencies. ```yaml dependencies: laconic: ^2.2.0 laconic_mysql: ^1.2.0 ``` -------------------------------- ### Basic Query - Laconic Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of a basic query in Laconic, demonstrating alignment with Laravel. ```dart final users = await laconic .table('users') .where('age', 18, comparator: '>') .whereIn('status', ['active', 'pending']) .orderBy('created_at', direction: 'desc') .limit(10) .get(); ``` -------------------------------- ### Installation Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_sqlite/README.md Add laconic and laconic_sqlite to your pubspec.yaml dependencies. ```yaml dependencies: laconic: ^2.2.0 laconic_sqlite: ^1.2.0 ``` -------------------------------- ### Query Listener Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_mysql/README.md Example of how to add a query listener for debugging purposes. ```dart final laconic = Laconic( MysqlDriver(MysqlConfig( database: 'my_database', password: 'password', )), listen: (query) { print('SQL: ${query.sql}'); print('Bindings: ${query.bindings}'); }, ); ``` -------------------------------- ### Query Listener Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_postgresql/README.md Example of how to add a query listener for debugging purposes. ```dart final laconic = Laconic( PostgresqlDriver(PostgresqlConfig( database: 'my_database', password: 'password', )), listen: (query) { print('SQL: ${query.sql}'); print('Bindings: ${query.bindings}'); }, ); ``` -------------------------------- ### Installation Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Add the laconic package and your chosen driver to your pubspec.yaml file. ```yaml dependencies: laconic: ^2.2.0 laconic_sqlite: ^1.1.0 # Or your preferred driver ``` -------------------------------- ### YAML Installation Source: https://github.com/calsranna/laconic/blob/main/README.md Add the core package and the driver you need to your pubspec.yaml file. ```yaml dependencies: laconic: ^2.2.0 laconic_sqlite: ^1.1.0 # For SQLite # laconic_mysql: ^1.2.0 # For MySQL # laconic_postgresql: ^1.2.0 # For PostgreSQL ``` -------------------------------- ### Usage Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_postgresql/README.md Example of how to use the laconic_postgresql driver to perform basic CRUD operations. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_postgresql/laconic_postgresql.dart'; void main() async { final laconic = Laconic(PostgresqlDriver(PostgresqlConfig( host: '127.0.0.1', port: 5432, database: 'my_database', username: 'postgres', password: 'password', ))); // Query users final users = await laconic.table('users').where('active', true).get(); // Insert data final id = await laconic.table('users').insertGetId({ 'name': 'John', 'age': 25, }); // Update data await laconic.table('users').where('id', id).update({'age': 26}); // Delete data await laconic.table('users').where('id', id).delete(); // Don't forget to close await laconic.close(); } ``` -------------------------------- ### Basic WHERE clause Source: https://github.com/calsranna/laconic/blob/main/README.md Example of a basic WHERE clause with a comparator. ```dart final adults = await laconic.table('users') .where('age', 18, comparator: '>=') .get(); ``` -------------------------------- ### Running Tests Source: https://github.com/calsranna/laconic/blob/main/README.md Commands for running tests for the Laconic project, including specific packages and Docker setup. ```bash # Run all tests dart test # Run specific package tests dart test packages/laconic/test dart test packages/laconic_sqlite/test dart test packages/laconic_mysql/test dart test packages/laconic_postgresql/test # Start Docker containers for MySQL/PostgreSQL testing docker-compose up -d dart test docker-compose down ``` -------------------------------- ### Transactions Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_sqlite/README.md Example demonstrating how to perform database operations within a transaction. ```dart await laconic.transaction(() async { final userId = await laconic.table('users').insertGetId({ 'name': 'Test User', }); await laconic.table('posts').insert([ {'user_id': userId, 'title': 'First Post'}, ]); }); ``` -------------------------------- ### OR WHERE clauses Source: https://github.com/calsranna/laconic/blob/main/README.md Example of using OR WHERE clauses. ```dart final users = await laconic.table('users') .where('role', 'admin') .orWhere('role', 'moderator') .get(); ``` -------------------------------- ### Custom Driver Implementation Source: https://github.com/calsranna/laconic/blob/main/README.md An example of how to create a custom database driver by implementing the DatabaseDriver interface. ```dart class MyDriver implements DatabaseDriver { @override SqlGrammar get grammar => MyGrammar(); @override Future> select(String sql, [List params = const []]) async { // Implementation } // Implement other methods... } ``` -------------------------------- ### Query Listener Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_sqlite/README.md Example of adding a query listener for debugging purposes. ```dart final laconic = Laconic( SqliteDriver(SqliteConfig('app.db')), listen: (query) { print('SQL: ${query.sql}'); print('Bindings: ${query.bindings}'); }, ); ``` -------------------------------- ### Dependency Management Commands Source: https://github.com/calsranna/laconic/blob/main/CLAUDE.md Bash commands for getting and upgrading project dependencies. ```bash # Get dependencies dart pub get # Update dependencies dart pub upgrade ``` -------------------------------- ### Complex JOIN - Laconic Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of a complex JOIN query in Laconic, showing full support. ```dart final results = await laconic .table('users u') .select(['u.name', 'p.title']) .join('posts p', (join) { join.on('u.id', 'p.user_id') .where('p.published', true); }) .leftJoin('comments c', (join) { join.on('c.post_id', 'p.id'); }) .get(); ``` -------------------------------- ### Aggregation Query - Laconic Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of aggregation queries in Laconic, noting the need for multiple queries for equivalent results. ```dart final count = await laconic.table('orders').where('status', 'completed').count(); final avgAmount = await laconic.table('orders').where('status', 'completed').avg('amount'); final maxAmount = await laconic.table('orders').where('status', 'completed').max('amount'); ``` -------------------------------- ### Count records Source: https://github.com/calsranna/laconic/blob/main/README.md Example of counting the number of records in a table. ```dart final count = await laconic.table('users').count(); ``` -------------------------------- ### Usage Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_mysql/README.md Example of how to use the laconic_mysql driver for common database operations like querying, inserting, updating, and deleting data. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_mysql/laconic_mysql.dart'; void main() async { final laconic = Laconic(MysqlDriver(MysqlConfig( host: '127.0.0.1', port: 3306, database: 'my_database', username: 'root', password: 'password', ))); // Query users final users = await laconic.table('users').where('active', true).get(); // Insert data final id = await laconic.table('users').insertGetId({ 'name': 'John', 'age': 25, }); // Update data await laconic.table('users').where('id', id).update({'age': 26}); // Delete data await laconic.table('users').where('id', id).delete(); // Don't forget to close await laconic.close(); } ``` -------------------------------- ### Complex JOIN - Laravel Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of a complex JOIN query in Laravel. ```php $results = DB::table('users u') ->join('posts p', function($join) { $join->on('u.id', '=', 'p.user_id') ->where('p.published', true); }) ->leftJoin('comments c', 'c.post_id', '=', 'p.id') ->select('u.name', 'p.title') ->get(); ``` -------------------------------- ### Custom Database Driver Implementation Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Example of how to implement a custom database driver by extending the DatabaseDriver class. ```dart class MyDriver implements DatabaseDriver { @override SqlGrammar get grammar => MyGrammar(); @override Future> select(String sql, [List params = const []]) async { // Implementation } @override Future statement(String sql, [List params = const []]) async { // Implementation } @override Future insertAndGetId(String sql, [List params = const []]) async { // Implementation } @override Future transaction(Future Function() action) async { // Implementation } @override Future close() async { // Implementation } } ``` -------------------------------- ### Aggregation Query - Laravel Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of an aggregation query in Laravel using DB::raw. ```php $stats = DB::table('orders') ->where('status', 'completed') ->select([ DB::raw('COUNT(*) as count'), DB::raw('AVG(amount) as avg_amount'), DB::raw('MAX(amount) as max_amount') ]) ->first(); ``` -------------------------------- ### Select specific columns Source: https://github.com/calsranna/laconic/blob/main/README.md Example of selecting only specific columns from a table. ```dart final names = await laconic.table('users').select(['name', 'age']).get(); ``` -------------------------------- ### WHERE BETWEEN clause Source: https://github.com/calsranna/laconic/blob/main/README.md Example of using a WHERE BETWEEN clause to specify a range. ```dart final users = await laconic.table('users') .whereBetween('age', min: 18, max: 30) .get(); ``` -------------------------------- ### Usage Source: https://github.com/calsranna/laconic/blob/main/packages/laconic_sqlite/README.md Example demonstrating how to use laconic_sqlite for database operations like querying, inserting, updating, and deleting data. It shows both file-based and in-memory database configurations. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_sqlite/laconic_sqlite.dart'; void main() async { // Create a file-based database final laconic = Laconic(SqliteDriver(SqliteConfig('app.db'))); // Or use an in-memory database // final laconic = Laconic(SqliteDriver(SqliteConfig(':memory:'))); // Query users final users = await laconic.table('users').where('active', true).get(); // Insert data final id = await laconic.table('users').insertGetId({ 'name': 'John', 'age': 25, }); // Update data await laconic.table('users').where('id', id).update({'age': 26}); // Delete data await laconic.table('users').where('id', id).delete(); // Don't forget to close await laconic.close(); } ``` -------------------------------- ### Multiple WHERE clauses (AND) Source: https://github.com/calsranna/laconic/blob/main/README.md Example of using multiple WHERE clauses, which are combined with AND. ```dart final results = await laconic.table('users') .where('age', 18, comparator: '>') .where('status', 'active') .get(); ``` -------------------------------- ### INNER JOIN Source: https://github.com/calsranna/laconic/blob/main/README.md Example of performing an INNER JOIN operation between two tables. ```dart final results = await laconic.table('users u') .select(['u.name', 'p.title']) .join('posts p', (join) => join.on('u.id', 'p.user_id')) .get(); ``` -------------------------------- ### Insert, Update, Delete Operations Source: https://github.com/calsranna/laconic/blob/main/README.md Examples of performing insert, update, and delete operations on a table using Laconic. ```dart // Insert await laconic.table('users').insert([ {'name': 'John', 'age': 25}, ]); // Insert and get ID final id = await laconic.table('users').insertGetId({ 'name': 'Jane', 'age': 30, }); // Update await laconic.table('users') .where('id', 1) .update({'name': 'New Name'}); // Delete await laconic.table('users') .where('id', 99) .delete(); // Note: delete(), increment(), and decrement() require a WHERE clause by default // to prevent accidental mass operations. To explicitly allow without WHERE: // await laconic.table('users').delete(allowWithoutWhere: true); ``` -------------------------------- ### LEFT JOIN with conditions Source: https://github.com/calsranna/laconic/blob/main/README.md Example of performing a LEFT JOIN operation with additional conditions. ```dart final results = await laconic.table('users u') .select(['u.name', 'p.title']) .leftJoin( 'posts p', (join) => join .on('u.id', 'p.user_id') .where('p.status', 'published'), ) .get(); ``` -------------------------------- ### WHERE IN clause Source: https://github.com/calsranna/laconic/blob/main/README.md Example of using a WHERE IN clause to match multiple values. ```dart final users = await laconic.table('users') .whereIn('id', [1, 2, 3]) .get(); ``` -------------------------------- ### Check if records exist Source: https://github.com/calsranna/laconic/blob/main/README.md Example of checking if any records exist that match a condition. ```dart final exists = await laconic.table('users').where('id', 1).exists(); ``` -------------------------------- ### Advanced Conditions in JOIN - Laravel Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of advanced conditions within a JOIN clause in Laravel. ```php $results = DB::table('users u') ->join('posts p', function($join) { $join->on('u.id', '=', 'p.user_id') ->whereIn('p.status', ['published', 'draft']) ->whereNotNull('p.content'); }) ->get(); ``` -------------------------------- ### Advanced Conditions in JOIN - Laconic Source: https://github.com/calsranna/laconic/blob/main/doc/COMPARISON_REPORT.md Example of advanced conditions within a JOIN clause in Laconic, demonstrating full support. ```dart final results = await laconic .table('users u') .select(['u.name', 'p.title']) .join('posts p', (join) { join.on('u.id', 'p.user_id') .whereIn('p.status', ['published', 'draft']) .whereNotNull('p.content'); }) .get(); ``` -------------------------------- ### WHERE NULL / NOT NULL clause Source: https://github.com/calsranna/laconic/blob/main/README.md Example of using WHERE NULL or WHERE NOT NULL clauses. ```dart final usersWithEmail = await laconic.table('users') .whereNotNull('email') .get(); ``` -------------------------------- ### Insert and Get ID Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Insert a record and retrieve the auto-generated ID. ```dart final id = await laconic.table('users').insertGetId({ 'name': 'Jane', 'age': 30, }); ``` -------------------------------- ### Running Tests Source: https://github.com/calsranna/laconic/blob/main/CLAUDE.md Instructions for running tests for different database types, including SQLite and those requiring Docker for MySQL and PostgreSQL. ```bash # SQLite only (no Docker required) cd packages/laconic_sqlite && dart test # All databases (requires Docker) docker-compose up -d cd packages/laconic_mysql && dart test cd packages/laconic_postgresql && dart test docker-compose down ``` -------------------------------- ### Migration from 1.x to 2.0 Source: https://github.com/calsranna/laconic/blob/main/README.md Illustrates the syntax change for initializing Laconic with a specific database driver between version 1.x and 2.0. ```dart import 'package:laconic/laconic.dart'; import 'package:laconic_mysql/laconic_mysql.dart'; final laconic = Laconic(MysqlDriver(MysqlConfig(...))); ``` -------------------------------- ### Testing Commands Source: https://github.com/calsranna/laconic/blob/main/CLAUDE.md Common bash commands for running tests, managing Docker containers, and performing specific test runs. ```bash # Run all tests across all packages dart test # Run specific database tests cd packages/laconic_sqlite && dart test cd packages/laconic_mysql && dart test cd packages/laconic_postgresql && dart test # Run specific test by name dart test --name "test_name" # Start MySQL and PostgreSQL containers for testing docker-compose up -d # Stop containers docker-compose down ``` -------------------------------- ### Insert Records Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Insert new records into a table. ```dart await laconic.table('users').insert([ {'name': 'John', 'age': 25}, ]); ``` -------------------------------- ### Ordering and Limiting Results Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Order results by multiple columns, limit the number of records, and skip records using offset. ```dart final users = await laconic.table('users') .orderBy('name') .orderByDesc('created_at') .limit(10) .offset(20) .get(); ``` -------------------------------- ### CROSS JOIN Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Perform a CROSS JOIN operation between two tables. ```dart final results = await laconic.table('users') .crossJoin('roles') .get(); ``` -------------------------------- ### Min Column Value Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Find the minimum value in a specific column. ```dart final lowest = await laconic.table('scores').min('score'); ``` -------------------------------- ### Sum Column Values Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Calculate the sum of values in a specific column. ```dart final total = await laconic.table('orders').sum('amount'); ``` -------------------------------- ### Code Analysis Commands Source: https://github.com/calsranna/laconic/blob/main/CLAUDE.md Bash commands for running static analysis and applying automatic code fixes. ```bash # Run static analysis dart analyze # Apply automatic fixes dart fix --apply ``` -------------------------------- ### WHERE Column Comparison Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Filter records by comparing two columns. ```dart final users = await laconic.table('users') .whereColumn('created_at', 'updated_at', operator: '<') .get(); ``` -------------------------------- ### RIGHT JOIN Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Perform a RIGHT JOIN operation between two tables. ```dart final results = await laconic.table('users u') .rightJoin('posts p', (join) => join.on('u.id', 'p.user_id')) .get(); ``` -------------------------------- ### Max Column Value Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Find the maximum value in a specific column. ```dart final highest = await laconic.table('scores').max('score'); ``` -------------------------------- ### Allow Delete Without WHERE Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Explicitly allow delete operations without a WHERE clause (use with caution). ```dart await laconic.table('users').delete(allowWithoutWhere: true); ``` -------------------------------- ### Update Records Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Update existing records in a table based on a condition. ```dart await laconic.table('users') .where('id', 1) .update({'name': 'New Name'}); ``` -------------------------------- ### Average Column Values Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Calculate the average of values in a specific column. ```dart final average = await laconic.table('products').avg('price'); ``` -------------------------------- ### Delete Records Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Delete records from a table based on a condition. ```dart await laconic.table('users') .where('id', 99) .delete(); ``` -------------------------------- ### Distinct Select Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Retrieve distinct values for a specified column. ```dart final roles = await laconic.table('users').distinct().select(['role']).get(); ``` -------------------------------- ### Increment / Decrement Column Values Source: https://github.com/calsranna/laconic/blob/main/packages/laconic/README.md Atomically increment or decrement a column's value. ```dart await laconic.table('posts').where('id', 1).increment('views'); await laconic.table('products').where('id', 1).decrement('stock', amount: 5); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.