### Initialize Installation Prefix Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt Sets the installation prefix to a bundle directory. This ensures that the 'installing' process creates a relocatable bundle in the build directory. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Application Executable Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs the main application executable to the specified runtime destination. This makes the executable available after the installation process. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Library Installation Path Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt Configures the installation path for bundled libraries relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Define Installation Directories Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Defines variables for the installation directories of bundle data and libraries. These paths are used to organize installed files relative to the installation prefix. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Flutter Library Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs the main Flutter library file to the root of the application bundle. This makes the core Flutter runtime accessible. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Bundle Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Configures the installation prefix to be next to the executable for in-place running. This is essential for Visual Studio builds and ensures support files are correctly located. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Bundled Libraries Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt Installs all bundled libraries for plugins into the lib directory of the bundle. This ensures that all necessary plugin dependencies are included. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Get Category Object from Product Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md This example demonstrates how to retrieve the associated Category object from a Product instance. ```dart flutter -> Product.getCategory(); ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs any bundled plugin libraries to the application bundle's library directory. This ensures that plugins with external library dependencies are correctly deployed. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Check PkgConfig Modules Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/flutter/CMakeLists.txt Checks for required GTK, GLIB, and GIO modules using PkgConfig. Ensure these libraries are installed on your system. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Select All Products Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Retrieves all records from the 'Products' table and prints each record as a map. This is a basic example of querying data. ```dart final productList = await Product().select().toList(); for (int i = 0; i < productList.length; i++) { print(productList[i].toMap()); } ``` -------------------------------- ### Install AOT Library Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for Profile and Release configurations. This optimizes runtime performance for non-debug builds. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Listing Saved Products with saveAll Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md This example demonstrates listing saved products using the saveAll method, displaying product details including ID, name, description, price, and category. ```dart flutter EXAMPLE 5.4: listing saved products (set rownum=i) with saveAll method; flutter {id: 1, name: Notebook 12", description: 128 GB SSD i7, price: 6899.0, isActive: true, categoryId: 1, rownum: 1, isDeleted: false} flutter {id: 2, name: Notebook 12", description: 256 GB SSD i7, price: 8244.0, isActive: true, categoryId: 1, rownum: 2, isDeleted: false} flutter {id: 3, name: Notebook 12", description: 512 GB SSD i7, price: 9214.0, isActive: true, categoryId: 1, rownum: 3, isDeleted: false} flutter {id: 4, name: Notebook 13", description: 128 GB SSD, price: 8500.0, isActive: true, categoryId: 1, rownum: 4, isDeleted: false} flutter {id: 5, name: Notebook 13", description: 256 GB SSD, price: 9900.0, isActive: true, categoryId: 1, rownum: 5, isDeleted: false} flutter {id: 6, name: Notebook 13", description: 512 GB SSD, price: 11000.0, isActive: true, categoryId: 1, rownum: 6, isDeleted: false} flutter {id: 7, name: Notebook 15", description: 128 GB SSD, price: 8999.0, isActive: true, categoryId: 1, rownum: 7, isDeleted: false} flutter {id: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: true, categoryId: 1, rownum: 8, isDeleted: false} flutter {id: 9, name: Notebook 15", description: 512 GB SSD, price: 11999.0, isActive: true, categoryId: 1, rownum: 9, isDeleted: false} flutter {id: 10, name: Ultrabook 13", description: 128 GB SSD i5, price: 9954.0, isActive: true, categoryId: 2, rownum: 10, isDeleted: false} flutter {id: 11, name: Ultrabook 13", description: 256 GB SSD i5, price: 11154.0, isActive: false, categoryId: 2, rownum: 11, isDeleted: false} flutter {id: 12, name: Ultrabook 13", description: 512 GB SSD i5, price: 13000.0, isActive: false, categoryId: 2, rownum: 12, isDeleted: false} flutter {id: 13, name: Ultrabook 15", description: 128 GB SSD i7, price: 11000.0, isActive: false, categoryId: 2, rownum: 13, isDeleted: false} flutter {id: 14, name: Ultrabook 15", description: 256 GB SSD i7, price: 12000.0, isActive: false, categoryId: 2, rownum: 14, isDeleted: false} flutter {id: 15, name: Ultrabook 15", description: 512 GB SSD i7 (updated), price: 14000.0, isActive: true, categoryId: 2, rownum: 15, isDeleted: false} flutter {id: 16, name: Product 1, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 16, isDeleted: false} flutter {id: 17, name: Product 2, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 17, isDeleted: false} flutter {id: 18, name: Product 3, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 18, isDeleted: false} flutter {id: 19, name: Product 4, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 19, isDeleted: false} flutter {id: 20, name: Product 5, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 20, isDeleted: false} ``` -------------------------------- ### Install Flutter Assets Directory Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt This snippet ensures the Flutter assets directory is fully removed and then re-copied during the installation process. This is crucial for avoiding stale assets from previous builds. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install( CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Complex Filter with AND, OR, and Brackets Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Construct complex queries using `and`, `or`, `startBlock`, and `endBlock` to group conditions. This example filters products by price greater than 10000 and either description containing '256' or starting with '512'. Use `toSingle` for queries expected to return one result. ```dart Product().select().price.greaterThan(10000).and.startBlock.description.contains("256").or.description.startsWith("512").endBlock.toSingle((product){ // TO DO }) ``` -------------------------------- ### Select All Products Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Example of selecting all rows from the 'products' table without any filters, using `Product().select().toList()`. Displays details of the found products. ```dart Product().select().toList() ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs the Flutter assets directory to the application's data directory. It first removes any existing assets to ensure a clean copy from the build directory. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Relationships: Getting Related Entities Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Demonstrates how to retrieve related entities using getter methods. For example, getting the category of a product or listing all products within a category. ```APIDOC ## Relationships ### Example 7.1: Get Category from Product ```dart final product = await Product().getById(1); final category = await product.getCategory(); print(category.toMap()); ``` **Results:** ```json {id: 1, name: Notebooks, isActive: true, isDeleted: false} ``` ### Example 7.2: Get Products of a Category ```dart final category = await Category().getById(1); final productList = await category.getProducts(); for(var product in productList) { print(product.toMap()); } ``` **Results:** Products of 'Notebooks' listing 9 matches found: ```json {id: 1, name: Notebook 12", description: 128 GB SSD i7, price: 6899.0, isActive: true, categoryId: 1, rownum: 1, isDeleted: false} {id: 2, name: Notebook 12", description: 256 GB SSD i7, price: 8244.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} .... ``` ``` -------------------------------- ### DEBUG RESULT of One-to-One Relationship Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity_gen/CHANGELOG.md Example output showing the structure of a product object that includes its one-to-one related property data. ```json flutter: { productId: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: false, categoryId: 1, rownum: 8, datetime: 2019-11-21 06:22:34.512, isDeleted: false, property: {stockQty: 4, weight: 320} } ``` -------------------------------- ### One-to-One Relationship Example Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/CHANGELOG.md Defines a one-to-one relationship between two tables using SqfEntityTable and SqfEntityFieldRelationship. Shows how to access and save related properties. ```dart const tableProductProperties = SqfEntityTable( tableName: 'property', primaryKeyName: 'propertyId', //useSoftDeleting: true, //primaryKeyType: PrimaryKeyType.integer_auto_incremental, fields: [ SqfEntityField('weight', DbType.real), SqfEntityField('stockQty', DbType.numeric), SqfEntityFieldRelationship( //fieldName: 'productId', parentTable: tableProduct, relationType: RelationType.ONE_TO_ONE) ], ); ``` ```dart final product = await Product().getById(8); product.property ..stockQty = 8 ..weight = 320; await product.save(); print(product.toMapWithChilds()); ``` ```json flutter: { productId: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: false, categoryId: 1, rownum: 8, datetime: 2019-11-21 06:22:34.512, isDeleted: false, property: {stockQty: 4, weight: 320} } ``` -------------------------------- ### Synchronize Data from Web and Upsert Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Fetch JSON data from a URL, load it into a list, and then use upsertAll() to save it to the local database. This example demonstrates fetching todos from a public API. ```dart todosList = await Todo.fromWebUrl("https://jsonplaceholder.typicode.com/todos"); final results = await Todo().upsertAll(todosList); // print upsert Results for (var res in results) { print(res.toString()); } todosList = await Todo().select().top(10).toList(); print(todosList.length.toString() + " matches found\n"); for (var todo in todosList) { print(todo.toMap()); } ``` -------------------------------- ### Project and Minimum CMake Version Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Sets the minimum required CMake version and the project name. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) ``` -------------------------------- ### SqfEntity Sequence Generation Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Demonstrates the usage of IdentitySequence to get the current value, generate the next value, and reset the sequence. ```dart final int currentVal = await IdentitySequence().currentVal(); final int nextVal = await IdentitySequence().nextVal(); final int nextVal2 = await IdentitySequence().nextVal(); final int currentVal2 = await IdentitySequence().currentVal(); // You can reset sequence anytime final int currentVal3 = await IdentitySequence().reset(); print(""" IdentitySequence().currentVal = $currentVal IdentitySequence().nextVal = $nextVal IdentitySequence().nextVal = $nextVal2 IdentitySequence().currentVal = $currentVal2 IdentitySequence().reset = $currentVal3 // returns start value """); ``` -------------------------------- ### Select All Products Without Filter Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md This example shows how to select all rows from the 'product' table without applying any filters, equivalent to `SELECT * FROM PRODUCTS`. It's useful for retrieving all product data. ```dart flutter EXAMPLE 1.1: SELECT ALL ROWS WITHOUT FILTER ex: SELECT * FROM PRODUCTS flutter -> Product().select().toList() flutter 20 matches found: flutter {id: 1, name: Notebook 12", description: 128 GB SSD i7, price: 6899.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 2, name: Notebook 12", description: 256 GB SSD i7, price: 8244.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 3, name: Notebook 12", description: 512 GB SSD i7, price: 9214.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 4, name: Notebook 13", description: 128 GB SSD, price: 8500.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 5, name: Notebook 13", description: 256 GB SSD, price: 9900.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 6, name: Notebook 13", description: 512 GB SSD, price: 11000.0, isActive: false, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 7, name: Notebook 15", description: 128 GB SSD, price: 8999.0, isActive: false, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: false, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 9, name: Notebook 15", description: 512 GB SSD, price: 11999.0, isActive: true, categoryId: 1, rownum: 0, isDeleted: false} flutter {id: 10, name: Ultrabook 13", description: 128 GB SSD i5, price: 9954.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 11, name: Ultrabook 13", description: 256 GB SSD i5, price: 11154.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 12, name: Ultrabook 13", description: 512 GB SSD i5, price: 13000.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 13, name: Ultrabook 15", description: 128 GB SSD i7, price: 11000.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 14, name: Ultrabook 15", description: 256 GB SSD i7, price: 12000.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 15, name: Ultrabook 15", description: 512 GB SSD i7, price: 14000.0, isActive: true, categoryId: 2, rownum: 0, isDeleted: false} flutter {id: 16, name: Product 1, description: , price: 0.0, isActive: true, categoryId: 0, rownum: 0, isDeleted: false} ``` -------------------------------- ### Delete Product if Exists Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md This example demonstrates deleting a product only if it is not null. It confirms the operation by returning the number of updated items. ```dart flutter -> if (product != null) Product.delete(); flutter 1 items updated ``` -------------------------------- ### Clean Build Bundle Directory Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt Removes the build bundle directory recursively before installation. This ensures a clean state for the bundle on each build. ```cmake install( CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Get Product by ID (Method 1) Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Fetches a single product record by its primary key using the getById() method. This is a direct way to retrieve a specific record. ```dart var product = await Product().getById(5); ``` -------------------------------- ### SqfEntityBuilderForm with Date Range and Soft Deleting Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/CHANGELOG.md Example of defining a `SqfEntityTable` with form generation capabilities, soft deleting enabled, and specific date range constraints for datetime fields. The `useSoftDeleting` option automatically adds an 'isDeleted' field. ```dart @SqfEntityBuilderForm(tableCategory, formListTitleField: 'name', hasSubItems: true) const tableCategory = SqfEntityTable( tableName: 'category', primaryKeyName: 'id', primaryKeyType: PrimaryKeyType.integer_auto_incremental, useSoftDeleting: true, // when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete) modelName: null, // SqfEntity will set it to TableName automatically when the modelName (class name) is null // declare fields fields: [ SqfEntityField('name', DbType.text), SqfEntityField('isActive', DbType.bool, defaultValue: true), SqfEntityField('date1', DbType.datetime, defaultValue: 'DateTime.now()', minValue: '2019-01-01', maxValue: '2023-01-01'), SqfEntityField('date2', DbType.datetime, minValue: '2020-01-01', maxValue: '2022-01-01') ]); ``` -------------------------------- ### SqfEntity Sequence Management Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Demonstrates the usage of SqfEntity's sequence features to get current, next, and reset sequence values. Note that nextVal() might return 0 if the sequence is reset or not properly initialized. ```dart flutter: final currentVal= await IdentitySequence().currentVal(); flutter: result: currentVal = 9 flutter: final nextVal = await IdentitySequence().nextVal(); flutter: result: nextVal = 10 flutter: final int nextVal2 = await IdentitySequence().nextVal(); flutter: result: nextVal2 = 0 flutter: final int currentVal2 = await IdentitySequence().currentVal(); flutter: result: currentVal2 = 0 flutter: final int currentVal3 = await IdentitySequence().reset(); flutter: result: currentVal3 = 0 ``` -------------------------------- ### Define Product Table Model with Relationship Source: https://github.com/hhtokpinar/sqfentity/wiki/Creating-SqfEntity-Table-Model Define the 'product' table model, including a relationship to the 'category' table. This example demonstrates foreign key constraints and sequenced fields. ```dart const tableProduct = SqfEntityTable( tableName: 'product', primaryKeyName: 'id', primaryKeyType: PrimaryKeyType.integer_auto_incremental, useSoftDeleting: true, fields: [ SqfEntityField('name', DbType.text), SqfEntityField('description', DbType.text), SqfEntityField('price', DbType.real, defaultValue: 0), SqfEntityField('isActive', DbType.bool, defaultValue: true), SqfEntityFieldRelationship( parentTable: tableCategory, deleteRule: DeleteRule.CASCADE, defaultValue: '0'), // Relationship column for CategoryId of Product SqfEntityField('rownum', DbType.integer, sequencedBy: seqIdentity /*Example of linking a column to a sequence */), SqfEntityField('imageUrl', DbType.text) ]); ``` -------------------------------- ### Define Todo Table for POST Request Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/CHANGELOG.md Define a constant for the 'todos' table, specifying its fields and a default JSON URL for synchronization. This setup is required before using the post() method. ```dart const tableTodo = SqfEntityTable( tableName: 'todos', primaryKeyName: 'id', primaryKeyType: PrimaryKeyType.integer_unique, defaultJsonUrl: 'https://jsonplaceholder.typicode.com/todos', // optional: to synchronize your table with json data from webUrl fields: [ SqfEntityField('userId', DbType.integer), SqfEntityField('title', DbType.text), SqfEntityField('completed', DbType.bool, defaultValue: false), ]); ``` -------------------------------- ### Database and Table Initialization Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Confirms the creation of the 'sampleORMx01.db' database and successful initialization of 'product', 'category', and 'todos' tables, including index creation for 'product.categoryId'. ```text flutter sampleORMx01.db created successfully flutter SQFENTITIY: Table named 'product' was initialized successfuly with create new table flutter SQFENTITIY: alterTableIndexesQuery => [CREATE INDEX IF NOT EXISTS IDXCategorycategoryId ON product (categoryId ASC)] flutter SQFENTITIY: Table named 'category' was initialized successfuly with create new table flutter SQFENTITIY: Table named 'todos' was initialized successfuly with create new table flutter SQFENTITIY: The database is ready for use ``` -------------------------------- ### Sample Paging with SQFEntity Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Demonstrates how to retrieve a paginated list of products. Specify the page number and items per page. ```dart Product().select().page(3,5).toList() ``` -------------------------------- ### Initialize SqfEntity Tables Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md This snippet shows the successful initialization of SqfEntity tables for 'category', 'product', and 'todos'. It indicates that the database models were created successfully and the database is ready for use. ```dart flutter >>>>>>>>>>>>>>>>>>>>>>>>>>>> SqfEntityTable of 'category' initialized successfuly flutter >>>>>>>>>>>>>>>>>>>>>>>>>>>> SqfEntityTable of 'product' initialized successfuly flutter >>>>>>>>>>>>>>>>>>>>>>>>>>>> SqfEntityTable of 'todos' initialized successfuly D/EGL_emulation( 6184): eglMakeCurrent: 0xe6ed49a0: ver 3 0 (tinfo 0xcf020470) flutter SQFENTITIY: [databaseTables] Model was created successfully. Create models.dart file in your project and press Ctrl+V to paste the model from the Clipboard flutter sampleORMx01.db created successfully flutter SQFENTITIY: Table named 'product' was initialized successfuly with create new table flutter SQFENTITIY: alterTableIndexesQuery => [CREATE INDEX IF NOT EXISTS IDXCategorycategoryId ON product (categoryId ASC)] flutter SQFENTITIY: Table named 'category' was initialized successfuly with create new table flutter SQFENTITIY: Table named 'todos' was initialized successfuly with create new table flutter SQFENTITIY: The database is ready for use ``` -------------------------------- ### Listing Saved Products with SQFEntity Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Shows how to list saved products using the saveAll method. The output displays the details of each product, including its ID, name, description, price, and other attributes. ```dart flutter {id: 1, name: Notebook 12", description: 128 GB SSD i7, price: 6899.0, isActive: true, categoryId: 1, rownum: 1, isDeleted: false} flutter {id: 2, name: Notebook 12", description: 256 GB SSD i7, price: 8244.0, isActive: true, categoryId: 1, rownum: 2, isDeleted: false} flutter {id: 3, name: Notebook 12", description: 512 GB SSD i7, price: 9214.0, isActive: true, categoryId: 1, rownum: 3, isDeleted: false} flutter {id: 4, name: Notebook 13", description: 128 GB SSD, price: 8500.0, isActive: true, categoryId: 1, rownum: 4, isDeleted: false} flutter {id: 5, name: Notebook 13", description: 256 GB SSD, price: 9900.0, isActive: true, categoryId: 1, rownum: 5, isDeleted: false} flutter {id: 6, name: Notebook 13", description: 512 GB SSD, price: 11000.0, isActive: true, categoryId: 1, rownum: 6, isDeleted: false} flutter {id: 7, name: Notebook 15", description: 128 GB SSD, price: 8999.0, isActive: true, categoryId: 1, rownum: 7, isDeleted: false} flutter {id: 8, name: Notebook 15", description: 256 GB SSD, price: 10499.0, isActive: true, categoryId: 1, rownum: 8, isDeleted: false} flutter {id: 9, name: Notebook 15", description: 512 GB SSD, price: 11999.0, isActive: true, categoryId: 1, rownum: 9, isDeleted: false} flutter {id: 10, name: Ultrabook 13", description: 128 GB SSD i5, price: 9954.0, isActive: true, categoryId: 2, rownum: 10, isDeleted: false} flutter {id: 11, name: Ultrabook 13", description: 256 GB SSD i5, price: 11154.0, isActive: false, categoryId: 2, rownum: 11, isDeleted: false} flutter {id: 12, name: Ultrabook 13", description: 512 GB SSD i5, price: 13000.0, isActive: false, categoryId: 2, rownum: 12, isDeleted: false} flutter {id: 13, name: Ultrabook 15", description: 128 GB SSD i7, price: 11000.0, isActive: false, categoryId: 2, rownum: 13, isDeleted: false} flutter {id: 14, name: Ultrabook 15", description: 256 GB SSD i7, price: 12000.0, isActive: false, categoryId: 2, rownum: 14, isDeleted: false} flutter {id: 15, name: Ultrabook 15", description: 512 GB SSD i7 (updated), price: 14000.0, isActive: true, categoryId: 2, rownum: 15, isDeleted: false} flutter {id: 16, name: Product 1, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 16, isDeleted: false} flutter {id: 17, name: Product 2, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 17, isDeleted: false} flutter {id: 18, name: Product 3, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 18, isDeleted: false} flutter {id: 19, name: Product 4, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 19, isDeleted: false} flutter {id: 20, name: Product 5, description: , price: 0.0, isActive: false, categoryId: 0, rownum: 20, isDeleted: false} ``` -------------------------------- ### Database Initializer Method Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md The `main` function includes a call to `runSamples()`, which implicitly handles database initialization. Ensure the database is initialized correctly; check the debug console for any alerts. ```dart void main(List args) async { runSamples(); // If the database is not initialized, something went wrong. Check DEBUG CONSOLE for alerts } } ``` -------------------------------- ### Install ICU Data File Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/CMakeLists.txt Installs the ICU data file to the data directory of the application bundle. This file is required for internationalization and localization features. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Import SqfEntity and necessary packages Source: https://github.com/hhtokpinar/sqfentity/wiki/Creating-SqfEntity-Table-Model Import SqfEntity and other required packages in your model.dart file. Include dart:typed_data for blob types if needed. ```dart import 'dart:convert'; import 'dart:typed_data'; // for blob types. You can remove this if unnecessary import 'package:flutter/foundation.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'package:sqfentity/sqfentity.dart'; import 'package:sqfentity_gen/sqfentity_gen.dart'; ``` -------------------------------- ### Add Product Record (Detailed) Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Shows how to add a new record to the 'Product' table by instantiating a Product object and setting its properties before saving. ```dart final product = Product(); product.name = "Notebook 12\""; product.description = "128 GB SSD i7"; product.price = 6899; product.categoryId = notebookCategoryId; await product.save(); ``` -------------------------------- ### Import Existing SQLite Database with SqfEntity Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Converts an existing SQLite database to a SqfEntity model. This involves specifying the database name and the path to the bundled database file. ```dart class BundledDbModel extends SqfEntityModelProvider {} final bundledDbModel = await convertDatabaseToModelBase(BundledDbModel() ..databaseName = 'chinook.db' ..bundledDatabasePath = 'assets/chinook.sqlite'); ``` -------------------------------- ### Install AOT Library on Non-Debug Builds Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt This configuration installs the AOT (Ahead-Of-Time) compiled library. It is conditionally included only when the build type is not 'Debug', ensuring optimized performance for release builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### SqfEntity Model Generation Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Provides instructions for generating the 'models.dart' file using the clipboard after successful model creation by SqfEntity. ```text flutter SQFENTITIY: [databaseTables] Model was created successfully. Create models.dart file in your project and press Ctrl+V to paste the model from the Clipboard ``` -------------------------------- ### SqfEntityField with DateTime DbType Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/CHANGELOG.md Example of defining a field with the 'datetime' DbType for storing date and time. ```dart SqfEntityField('birthDate', DbType.datetime) ``` -------------------------------- ### SqfEntityField with Date DbType Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/CHANGELOG.md Example of defining a field with the 'date' DbType for storing small dates. ```dart SqfEntityField('birthDate', DbType.date) ``` -------------------------------- ### Update Single Record Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Updates a specific product record. This example shows updating a product with id 15. ```dart Product().select().id.equals(15).update({"description": "512 GB SSD i7 (updated)"}) ``` -------------------------------- ### Add Product Records (Quickly) Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Illustrates the quick addition of multiple product records using the Product.withFields constructor for concise data entry. ```dart await Product.withFields( "Notebook 12\"", "128 GB SSD i7", 6899, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 12\"", "256 GB SSD i7", 8244, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 12\"", "512 GB SSD i7", 9214, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "128 GB SSD", 8500, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "256 GB SSD", 9900, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "512 GB SSD", 11000, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "128 GB SSD", 8999, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "256 GB SSD", 10499, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "512 GB SSD", 11999, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "128 GB SSD i5", 9954, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "256 GB SSD i5", 11154, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "512 GB SSD i5", 13000, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "128 GB SSD i7", 11000, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "256 GB SSD i7", 12000, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "512 GB SSD i7", 14000, true, ultrabookCategoryId, 0, false).save(); ``` -------------------------------- ### Define Product Table with Constraints and Index Source: https://github.com/hhtokpinar/sqfentity/wiki/SQLite---Constraints-&-Index-Support Defines a sample 'product' table using SqfEntityField, incorporating NOT NULL, UNIQUE, INDEX, DEFAULT, and CHECK constraints. ```dart const tableProduct = SqfEntityTable( tableName: 'product', primaryKeyName: 'id', primaryKeyType: PrimaryKeyType.integer_auto_incremental, fields: [ SqfEntityField('name',DbType.text, isUnique: true, isNotNull: true, isIndex:true), SqfEntityField('price', DbType.real, defaultValue: 1, checkCondition: '(this)>0'), ]); ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the executable target. This can be customized if the application requires different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Get Category from Product Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Fetches the category associated with a specific product. Ensure the Product model and its getById method are available. ```dart final product = await Product().getById(1); final category = await product.getCategory(); print(category.toMap()); ``` -------------------------------- ### Create and Save Product Records Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Shows how to create new product records, either by instantiating the Product class and setting properties individually, or by using the withFields constructor for a more concise entry. The save() method persists the record to the database. ```dart final product = Product(); product.name = "Notebook 12\""; product.description = "128 GB SSD i7"; product.price = 6899; product.categoryId = notebookCategoryId; await product.save(); ``` ```dart await Product.withFields( "Notebook 12\"", "128 GB SSD i7", 6899, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 12\"", "256 GB SSD i7", 8244, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 12\"", "512 GB SSD i7", 9214, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "128 GB SSD", 8500, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "256 GB SSD", 9900, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 13\"", "512 GB SSD", 11000, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "128 GB SSD", 8999, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "256 GB SSD", 10499, null, notebookCategoryId, 0, false).save(); await Product.withFields( "Notebook 15\"", "512 GB SSD", 11999, true, notebookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "128 GB SSD i5", 9954, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "256 GB SSD i5", 11154, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 13\"", "512 GB SSD i5", 13000, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "128 GB SSD i7", 11000, true, ultrabookCategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "256 GB SSD i7", 12000, true, ultrabookcategoryId, 0, false).save(); await Product.withFields( "Ultrabook 15\"", "512 GB SSD i7", 14000, true, ultrabookCategoryId, 0, false).save(); ``` -------------------------------- ### Import necessary packages for model definition Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Import required packages for defining SqfEntity models. Ensure helper.dart and view.list.dart are in the correct directories. ```dart import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'package:sqfentity/sqfentity.dart'; import 'package:sqfentity_gen/sqfentity_gen.dart'; import '../tools/helper.dart'; import 'view.list.dart'; ``` -------------------------------- ### SqfEntity Sequence Operations Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Demonstrates the usage of `IdentitySequence` for managing auto-incrementing values. Includes getting current and next values, and resetting the sequence. ```dart final int currentVal = await IdentitySequence().currentVal(); final int nextVal = await IdentitySequence().nextVal(); final int nextVal2 = await IdentitySequence().nextVal(); final int currentVal2 = await IdentitySequence().currentVal(); // You can reset sequence anytime final int currentVal3 = await IdentitySequence().reset(); print("\n IdentitySequence().currentVal = $currentVal IdentitySequence().nextVal = $nextVal IdentitySequence().nextVal = $nextVal2 IdentitySequence().currentVal = $currentVal2 IdentitySequence().reset = $currentVal3 // returns start value "); ``` -------------------------------- ### Recover Many Products by Filter with SQFEntity Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Demonstrates recovering multiple products that match a specified filter. This is useful for undoing deletions or restoring data. ```dart -> Product().select().id.greaterThan(17).recover() flutter 3 items updated ``` -------------------------------- ### Delete Multiple Records with Query Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Delete multiple records that match a query condition. This example deletes all products with an ID greater than 17. ```dart final result = await Product().select().id.greaterThan(17).delete(); print(result.toString()); ``` -------------------------------- ### List All Categories Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Demonstrates how to fetch and list all categories from the database using the `select().toList()` method. This is typically used for displaying a list of categories on the home screen. ```dart flutter LISTING CATEGORIES -> Category().select().toList() flutter 2 matches found: flutter {id: 1, name: Notebooks, isActive: true, isDeleted: false} flutter {id: 2, name: Ultrabooks, isActive: true, isDeleted: false} ``` -------------------------------- ### Cross-Building Root Filesystem Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/linux/CMakeLists.txt Sets up the root filesystem for cross-building by defining CMAKE_SYSROOT and related find root path modes when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Get Related Category Object with SQFEntity Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Shows how to retrieve the related category object for a product. This demonstrates establishing and utilizing relationships between database entities. ```dart -> Product.getCategory(); ``` -------------------------------- ### Import necessary packages for sqfEntity model Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Import the required packages for defining sqfEntity models. Ensure you have sqfentity and sqfentity_gen in your dependencies. ```dart import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'package:sqfentity/sqfentity.dart'; import 'package:sqfentity_gen/sqfentity_gen.dart'; import '../tools/helper.dart'; import 'view.list.dart'; ``` -------------------------------- ### Execute Custom SQL Query and Get DataTable Source: https://github.com/hhtokpinar/sqfentity/blob/master/README.md Use `execDataTable` to execute a SELECT query and retrieve results as a List of Maps, representing rows and columns. ```dart await MyDbModel().execDataTable('SELECT name, price FROM product order by price desc LIMIT 5'); ``` -------------------------------- ### Define C++ wrapper plugin sources Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/flutter/CMakeLists.txt Lists the C++ source files for the plugin registrar and transforms the list to prepend the wrapper root directory. ```cmake list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Add Dependency Libraries and Include Directories Source: https://github.com/hhtokpinar/sqfentity/blob/master/example/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds the source directory to include paths for the runner executable. Application-specific dependencies should be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### List Categories Source: https://github.com/hhtokpinar/sqfentity/blob/master/sqfentity/README.md Demonstrates how to select and list all categories using `Category().select().toList()`. Shows the count and details of matched categories. ```dart Category().select().toList() ```