sqfentity 0.1.0+5 sqfentity: ^0.1.0+5 copied to clipboard
SqfEntity ORM for Flutter/Dart lets you build and execute SQL commands easily and quickly with the help of fluent methods similar to .Net Entity Framework.
import 'example_db_model.dart';
import 'example_models.dart';
void main(List<String> args) async {
// 1- creates a simple Model named product and sets the clipboard for paste into your models.dart file
createSqfEntityModelString();
// 2- run Entity Model samples
// ATTENTION! when the software/app is started, you must check the database was it initialized.
// If needed, initilizeDb method runs CREATE / ALTER TABLE query for you.
final bool isInitialized = await MyDbModel().initializeDB();
if (isInitialized == true) {
runSamples();
// TO DO
// ex: runApp(MyApp());
} else {
// If the database is not initialized, something went wrong. Check DEBUG CONSOLE for alerts
// TO DO
}
}
void runSamples() async {
// add some products
await addSomeProducts();
// Print all categories
printCategories(false);
// SELECT AND ORDER PRODUCTS BY FIELDS
await samples1();
// FILTERS: SOME FILTERS ON PRODUCTS
await samples2();
// LIMITATIONS: PAGING, TOP X ROW
await samples3();
// DISTINCT, GROUP BY with SQL AGGREGATE FUNCTIONS,
await samples4();
// UPDATE BATCH, UPDATE OBJECT
await samples5();
// DELETE BATCH, DELETE OBJECT, RECOVERY
await samples6();
// ORM (Object Relational Mapping) SAMPLE
await samples7();
// fill List from the web (JSON)
await samples8();
}
void printCategories(bool getIsDeleted) {
Category().select(getIsDeleted: getIsDeleted).toList((categoryList) {
print("LISTING CATEGORIES -> Category().select().toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${categoryList.length} matches found:");
for (int i = 0; i < categoryList.length; i++) {
print(categoryList[i].toMap());
}
print(
"---------------------------------------------------------------\n\n");
return;
});
}
void createSqfEntityModelString() {
// To get the class from the clipboard, run it separately for each object
MyDbModel().createModel();
// create Model String and set the Clipboard (After debugging, press Ctrl+V to paste the model from the Clipboard)
}
void printProducts() async {
final productList = await Product().select().toList();
print(
"EXAMPLE 1.1: SELECT ALL ROWS WITHOUT FILTER ex: SELECT * FROM PRODUCTS \n -> Product().select().toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
}
Future<void> samples1() async {
// EXAMPLE 1.1: SELECT * FROM PRODUCTS
printProducts();
// EXAMPLE 1.2: ORDER BY FIELDS -> ex: SELECT * FROM PRODUCTS ORDER BY name, price DESC, id
var productList = await Product()
.select()
.orderBy("name")
.orderByDesc("price")
.orderBy("id")
.toList();
print(
"EXAMPLE 1.2: ORDER BY FIELDS ex: SELECT * FROM PRODUCTS ORDER BY name, price DESC, id \n-> Product().select().orderBy(\"name\").orderByDesc(\"price\").orderBy(\"id\").toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.3: SELECT SPECIFIC FIELDS -> ex: SELECT name,price FROM PRODUCTS ORDER BY price DESC
print(
"EXAMPLE 1.3: SELECT SPECIFIC FIELDS ex: SELECT name,price FROM PRODUCTS ORDER BY price DESC \n-> Product().select(columnsToSelect: [\"name\",\"price\"]).orderByDesc(\"price\").toList()");
productList = await Product()
.select(columnsToSelect: ["name", "price"])
.orderByDesc("price")
.toList();
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------");
}
Future<void> samples2() async {
// EXAMPLE 1.4: SELECT * FROM PRODUCTS WHERE isActive=1
var productList = await Product().select().isActive.equals(true).toList();
print(
"EXAMPLE 1.4: EQUALS ex: SELECT * FROM PRODUCTS WHERE isActive=1 \n-> Product().select().isActive.equals(true).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.5: SELECT * FROM PRODUCTS WHERE ID IN (3,6,9)
productList = await Product().select().id.inValues([3, 6, 9]).toList();
print(
"EXAMPLE 1.5: WHERE field IN (VALUES) ex: SELECT * FROM PRODUCTS WHERE ID IN (3,6,9) \n -> Product().select().id.inValues([3,6,9]).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// Brackets in query, Contains, Endswith, Startswith SAMPLES
// EXAMPLE 1.6: SELECT TOP 1 * FROM PRODUCTS WHERE price>10000 AND (description LIKE '%256%' OR description LIKE '512%')
final singleProduct = await Product()
.select()
.price
.greaterThan(10000)
.and
.startBlock
.description
.contains("256")
.or
.description
.startsWith("512")
.endBlock
.toSingle();
print(
"EXAMPLE 1.6: BRACKETS ex: SELECT TOP 1 * FROM PRODUCTS WHERE price>10000 AND (description LIKE '%256%' OR description LIKE '512%') \n -> Product().select().price.greaterThan(10000).and.startBlock.description.contains(\"256\").or.description.startsWith(\"512\").endBlock.toSingle((product){ // TO DO })");
print(
"Toplam " + (singleProduct != null ? "1" : "0") + " sonuç listeleniyor:");
if (singleProduct != null) {
print(singleProduct.toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.7: SELECT name,price FROM PRODUCTS WHERE price <=10000 AND (description LIKE '%128%' OR description LIKE '%GB')
productList = await Product()
.select()
.price
.lessThanOrEquals(10000)
.and
.startBlock
.description
.contains("128")
.or
.description
.endsWith("GB")
.or
.description
.startsWith("128")
.endBlock
.toList();
print(
"EXAMPLE 1.7: BRACKETS 2 ex: SELECT name,price FROM PRODUCTS WHERE price <=10000 AND (description LIKE '%128%' OR description LIKE '%GB') \n -> Product().select(columnsToSelect:[\"name\",\"price\"]).price.lessThanOrEquals(10000).and.startBlock.description.contains(\"128\").or.description.endsWith(\"GB\").endBlock.toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.8: NOT EQUALS
productList = await Product().select().id.not.equals(11).toList();
print(
"EXAMPLE 1.8: NOT EQUALS ex: SELECT * FROM PRODUCTS WHERE ID <> 11 \n -> Product().select().id.not.equals(11).toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.9: GREATERTHEN OR EQUALS, LESSTHAN OR EQUALS
productList = await Product()
.select()
.price
.greaterThanOrEquals(10000)
.and
.price
.lessThanOrEquals(13000)
.toList();
print(
"EXAMPLE 1.9: GREATERTHEN OR EQUALS, LESSTHAN OR EQUALS ex: SELECT * FROM PRODUCTS WHERE price>=10000 AND price<=13000 \n -> Product().select().price.greaterThanOrEquals(10000).and.price.lessThanOrEquals(13000).toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.10: BETWEEN KEYWORD
productList = await Product()
.select()
.price
.between(8000, 14000)
.orderBy("price")
.toList();
print(
"EXAMPLE 1.10: BETWEEN ex: SELECT * FROM PRODUCTS WHERE price BETWEEN 8000 AND 14000 \n -> Product().select().price.between(8000,14000).orderBy(\"price\").toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.11: 'NOT' KEYWORD
productList = await Product().select().id.not.greaterThan(5).toList();
print(
"EXAMPLE 1.11: 'NOT' KEYWORD ex: SELECT * FROM PRODUCTS WHERE NOT id>5 \n -> Product().select().id.not.greaterThan(5).toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.12: WRITING CUSTOM FILTER IN WHERE CLAUSE
productList =
await Product().select().where("id IN (3,6,9) OR price>8000").toList();
print(
"EXAMPLE 1.12: WRITING CUSTOM FILTER IN WHERE CLAUSE ex: SELECT * FROM PRODUCTS WHERE id IN (3,6,9) OR price>8000 \n -> Product().select().where(\"id IN (3,6,9) OR price>8000\").toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.13: Build filter and query from values from the form
// assume that the values come from the form by defining several variables:
int minPrice;
int maxPrice;
String nameContains;
String descriptionContains;
// setting values
minPrice =
8000; // if minPrice is null then -> The between method runs LessThanOrEquals Method
maxPrice =
10000; // if maxPrice is null then -> The between method runs GreaterThanOrEquals Method
nameContains =
"13"; // if all of the values any method's is null then -> this method will be extracted
descriptionContains = "SSD";
productList = await Product()
.select()
.price
.between(minPrice, maxPrice)
.and
.name
.contains(nameContains)
.and
.description
.contains(descriptionContains)
.toList();
print(
"EXAMPLE 1.13: Product().select().price.between($minPrice, $maxPrice).and.name.contains(\"$nameContains\").and.description.contains(\"$descriptionContains\").toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (var prod in productList) {
print(prod.toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.14: Select products with deleted items (only softdelete was activated on Model)
productList = await Product().select(getIsDeleted: true).toList();
print(
"EXAMPLE 1.14: EXAMPLE 1.13: Select products with deleted items\n -> Product().select(getIsDeleted: true).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (var prod in productList) {
print(prod.toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 1.15: Select products only deleted items (only softdelete was activated on Model)
productList = await Product()
.select(getIsDeleted: true)
.isDeleted
.equals(true)
.toList();
print(
"EXAMPLE 1.15: Select products only deleted items \n -> Product().select(getIsDeleted: true).isDeleted.equals(true).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (var prod in productList) {
print(prod.toMap());
}
print("---------------------------------------------------------------\n\n");
}
Future<void> samples3() async {
// EXAMPLE 3.1: SELECT TOP 3 * FROM PRODUCTS ORDER BY price DESC
var productList =
await Product().select().orderByDesc("price").top(3).toList();
print(
"EXAMPLE 3.1: LIMITATION ex: SELECT TOP 3 * FROM PRODUCTS ORDER BY price DESC \n -> Product().select().orderByDesc(\"price\").top(3).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 3.2: SAMPLE PAGING -> PRODUCTS in 3. page (5 items per page)
productList = await Product().select().page(3, 5).toList();
print(
"EXAMPLE 3.2: SAMPLE PAGING ex: PRODUCTS in 3. page (5 items per page) \n -> Product().select().page(3,5).toList()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
}
Future<void> samples4() async {
// EXAMPLE 4.1: SELECT DISTINCT name FROM PRODUCTS WHERE price > 3000
final productList = await Product()
.distinct(columnsToSelect: ["name"])
.price
.greaterThan(3000)
.toList();
print(
"EXAMPLE 4.1: DISTINCT ex: SELECT DISTINCT name FROM PRODUCTS WHERE price > 3000 \n -> Product().distinct(columnsToSelect:[\"name\").price.greaterThan(3000).toList();");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 4.2: GROUP BY with SCALAR OR AGGREGATE FUNCTIONS ex: SELECT COUNT(id) AS Count, MIN(price) AS minPrice, MAX(price) AS maxPrice, AVG(price) AS avgPrice FROM PRODUCTS GROUP BY name
// /* count(),avg(),max(),min() when empty returns columnname as default, count("aliasname") is returns alias columnname */
final objectList = await Product()
.select(columnsToSelect: [
ProductFields.name.toString(),
ProductFields.id.count("Count"),
ProductFields.price.min("minPrice"),
ProductFields.price.max("maxPrice"),
ProductFields.price.avg("avgPrice"),
ProductFields.price.sum("sumPrice"),
])
.groupBy(ProductFields.name
.toString() /*also you can use this .groupBy("name")*/)
.toListObject();
print(
"EXAMPLE 4.2: GROUP BY WITH SCALAR OR AGGREGATE FUNCTIONS ex: SELECT name, COUNT(id) AS Count, MIN(price) AS minPrice, MAX(price) AS maxPrice, AVG(price) AS avgPrice,ProductFields.price.sum(\"sumPrice\") FROM PRODUCTS GROUP BY name \n-> Product().select(columnsToSelect: [ProductFields.name.toString(), ProductFields.id.count(\"Count\"), ProductFields.price.min(\"minPrice\"), ProductFields.price.max(\"maxPrice\"), ProductFields.price.avg(\"avgPrice\")).groupBy(ProductFields.name.toString()).toListObject()");
// PRINT RESULTS TO DEBUG CONSOLE
print("${objectList.length} matches found:");
for (int i = 0; i < objectList.length; i++) {
print(objectList[i].toString());
}
print("---------------------------------------------------------------");
}
Future<void> samples5() async {
// EXAMPLE 5.1: Update multiple records with query
var result =
await Product().select().id.greaterThan(10).update({"isActive": 0});
print(
"EXAMPLE 5.1: Update multiple records with query \n -> Product().select().id.greaterThan(10).update({\"isActive\": 0});");
print(result.toString());
print("---------------------------------------------------------------\n\n");
// EXAMPLE 5.2: Update multiple records with query
result =
await Product().select().id.lessThanOrEquals(10).update({"isActive": 1});
print(
"EXAMPLE 5.2: uUpdate multiple records with query \n -> Product().select().id.lessThanOrEquals(10).update({\"isActive\": 1});");
print(result.toString());
print("---------------------------------------------------------------\n\n");
// EXAMPLE 5.3: select product by id and update
final product2 = await Product().getById(15);
// TO DO
// update product object if exist
if (product2 != null) {
product2.isActive = true;
product2.description += " (updated)";
await product2.save();
print("EXAMPLE 5.3: id=15 Product item updated: " +
product2.toMap().toString());
} else {
print("EXAMPLE 5.3: id=15 => product not found");
}
print("---------------------------------------------------------------\n\n");
// EXAMPLE 5.4: update some filtered products with saveAll method -> Product().saveAll(productList){});
var productList = await Product().select().toList();
int i = 0;
for (var product in productList) {
i++;
product.rownum = i;
}
final results = await Product().saveAll(productList);
productList = await Product().select().toList();
print(
"EXAMPLE 5.4: update some filtered products with saveAll method \n -> Product().saveAll(productList){});");
print(" List<BoolResult> result of saveAll method is following:");
for (var result in results) {
print(result.toString());
}
print("---------------------------------------------------------------");
print(
"EXAMPLE 5.4: listing saved products (set rownum=i) with saveAll method;");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------");
}
Future<void> samples6() async {
// EXAMPLE 6.1 : Delete all products.
// Uncomment following section for delete all products
/*
Product().select().delete().then((result) {
if (result.success)
print("${result.successMessage}");
else
print("${result.errorMessage}");
});
*/
// EXAMPLE 6.2: get product with query id and delete
var result = await Product().select().id.equals(16).delete();
print(
"EXAMPLE 6.2: delete product by query filder \n -> Product().select().id.equals(16).delete();");
print(result.toString());
print("---------------------------------------------------------------\n\n");
// EXAMPLE 6.3: Get product by id and then delete
final product = await Product().getById(17);
// TO DO
// delete product object if exist
if (product != null) {
result = await product.delete();
print(
"EXAMPLE 6.3: delete product if exist \n -> if (product != null) Product.delete();");
if (result.success) {
print("${result.successMessage}");
} else {
print("${result.errorMessage}");
}
print(
"---------------------------------------------------------------\n\n");
} else {
print("id=15 => product not found");
print(
"---------------------------------------------------------------\n\n");
}
// EXAMPLE 6.4: Delete many products by filter
result = await Product().select().id.greaterThan(17).delete();
print(
"EXAMPLE 6.4: Delete many products by filter \n -> Product().select().id.greaterThan(17).delete()");
if (result.success) {
print("${result.successMessage}");
} else {
print("${result.errorMessage}");
}
print("---------------------------------------------------------------\n\n");
/*/ EXAMPLE 6.5: Get product by id and then recover
Product().getById(17, (product) {
// TO DO
// delete product object if exist
if (product != null) {
product.delete().then((result) {
print(
"EXAMPLE 6.5: recover product if exist \n -> if (product != null) Product.recover();");
if (result.success)
print("${result.successMessage}");
else
print("${result.errorMessage}");
print(
"---------------------------------------------------------------\n\n");
});
} else {
print("id=15 => product not found");
print(
"---------------------------------------------------------------\n\n");
}
return;
});
*/
// EXAMPLE 6.6: Recover many products by filter
result = await Product().select().id.greaterThan(17).recover();
print(
"EXAMPLE 6.6: Recover many products by filter \n -> Product().select().id.greaterThan(17).recover()");
if (result.success) {
print("${result.successMessage}");
} else {
print("${result.errorMessage}");
}
print("---------------------------------------------------------------\n\n");
}
Future<void> samples7() async {
// EXAMPLE 7.1: goto Category Object from Product \n-> Product.category((_category) {});
final product = await Product().getById(3);
final category = await product.getCategory();
print(
"EXAMPLE 7.1: goto Category Object from Product \n-> Product.getCategory(); ");
print("The category of '${product.name}' is: " + category.toMap().toString());
// EXAMPLE 7.2: list Products of Categories \n-> Product.category((_category) {});
final categoryList = await Category().select().toList();
for (var category in categoryList) {
final productList = await category.getProducts();
print(
"EXAMPLE 7.2.${category.id}: Products of '${category.name}' listing \n-> category.getProducts((productList) {}); ");
// PRINT RESULTS TO DEBUG CONSOLE
print("${productList.length} matches found:");
for (int i = 0; i < productList.length; i++) {
print(productList[i].toMap());
}
print("---------------------------------------------------------------");
return;
}
return;
}
Future<void> samples8() async {
List<Todo> todosList = await Todo.fromWeb();
await Todo().upsertAll(todosList);
todosList = await Todo().select().top(10).toList();
print(
"EXAMPLE 8.1: Fill List from web (JSON data) and upsertAll \n -> Todo.fromWeb((todosList) {}");
print(todosList.length.toString() + " matches found\n");
for (var todo in todosList) {
print(todo.toMap());
}
print("---------------------------------------------------------------\n\n");
todosList =
await Todo.fromWebUrl("https://jsonplaceholder.typicode.com/todos");
final results = await Todo().upsertAll(todosList);
print(
"EXAMPLE 8.2: upsertAll result \n -> final results = await Todo().upsertAll(todosList);");
// print upsert Results
for (var res in results) {
res = res; // dummy line for analysis_options (unused_local_variable)
//print(res.toString()); // uncomment this line for print save results
}
todosList = await Todo().select().top(10).toList();
print(
"EXAMPLE 8.2: Fill List from web with Url (JSON data) and upsertAll \n -> Todo.fromWebUrl(\"https://jsonplaceholder.typicode.com/todos\", (todosList) {}");
print(todosList.length.toString() + " matches found\n");
for (var todo in todosList) {
print(todo.toMap());
}
print("---------------------------------------------------------------\n\n");
}
Future<void> addSomeProducts() async {
// add new categories if not any Category..
final category = await Category().select().toSingle();
if (category == null) {
await addCategories();
} else {
print(
"There is already categories in the database.. addCategories will not run");
}
// add new products if not any Product..
final product = await Product().select().toSingle();
if (product == null) {
await addProducts();
} else {
print(
"There is already products in the database.. addProduct will not run");
}
return;
}
Future<void> addCategories() async {
final notebookCategoryId =
await Category(name: "Notebooks", isActive: true).save();
print("new category with id=$notebookCategoryId added successfuly");
final ultrabookCategoryId =
await Category.withFields("Ultrabooks", true, false).save();
print("new category with id=$ultrabookCategoryId added successfuly");
}
Future<bool> addProducts() async {
final productList = await Product().select().toList();
if (productList.length < 15) {
// some dummy rows for select (id:1- to 15)
final product = Product();
product.name = "Notebook 12\"";
product.description = "128 GB SSD i7";
product.price = 6899;
product.categoryId = 1;
await product.save();
await Product.withFields(
"Notebook 12\"", "128 GB SSD i7", 6899, true, 1, 0, false)
.save();
await Product.withFields(
"Notebook 12\"", "256 GB SSD i7", 8244, true, 1, 0, false)
.save();
await Product.withFields(
"Notebook 12\"", "512 GB SSD i7", 9214, true, 1, 0, false)
.save();
await Product.withFields(
"Notebook 13\"", "128 GB SSD", 8500, true, 1, 0, false)
.save();
await Product.withFields(
"Notebook 13\"", "256 GB SSD", 9900, true, 1, 0, false)
.save();
await Product.withFields(
"Notebook 13\"", "512 GB SSD", 11000, null, 1, 0, false)
.save();
await Product.withFields(
"Notebook 15\"", "128 GB SSD", 8999, null, 1, 0, false)
.save();
await Product.withFields(
"Notebook 15\"", "256 GB SSD", 10499, null, 1, 0, false)
.save();
await Product.withFields(
"Notebook 15\"", "512 GB SSD", 11999, true, 1, 0, false)
.save();
await Product.withFields(
"Ultrabook 13\"", "128 GB SSD i5", 9954, true, 2, 0, false)
.save();
await Product.withFields(
"Ultrabook 13\"", "256 GB SSD i5", 11154, true, 2, 0, false)
.save();
await Product.withFields(
"Ultrabook 13\"", "512 GB SSD i5", 13000, true, 2, 0, false)
.save();
await Product.withFields(
"Ultrabook 15\"", "128 GB SSD i7", 11000, true, 2, 0, false)
.save();
await Product.withFields(
"Ultrabook 15\"", "256 GB SSD i7", 12000, true, 2, 0, false)
.save();
await Product.withFields(
"Ultrabook 15\"", "512 GB SSD i7", 14000, true, 2, 0, false)
.save();
print("added 15 new products");
// add a few dummy products for delete (id:16 to 20)
await Product.withFields("Product 1", "", 0, true, 0, 0, false).save();
await Product.withFields("Product 2", "", 0, true, 0, 0, false).save();
await Product.withFields("Product 3", "", 0, true, 0, 0, false).save();
await Product.withFields("Product 4", "", 0, true, 0, 0, false).save();
await Product.withFields("Product 5", "", 0, true, 0, 0, false).save();
print("added 5 dummy products");
}
return true;
}