Comments (11)
you can merge two or more fields with custom sql query using by columnsToSelect parameter
I've tested this code in my model:
final productList = await Product().select(columnsToSelect: ['(name || \' \' || description) AS name, isActive,price',]).toList();
printList(productList,isMap: true);
Note: each product's name = Notebook 12" and description changes between 128-512GB
DEBUG OUTPUT:
flutter: {name: Notebook 12" 128 GB SSD i7, isActive: 1, price: 6899.0}
flutter: {name: Notebook 12" 256 GB SSD i7, isActive: 1, price: 8244.0}
flutter: {name: Notebook 12" 512 GB SSD i7, isActive: 1, price: 9214.0}
from sqfentity.
Thanks. This solution is ok, but not practical in all situations. I can use this method only in aync method, and we need this in the widget's init method that is not async... So I need a solution without using await :-)
from sqfentity.
Ok. My job is already with the async side!
So do you have any suggestions? :-]
from sqfentity.
Maybe the easiest solution would be to add optional parameter to SqfEntityTable with custom code (as String) that would be added in the generated class?
from sqfentity.
Okay, I'm gonna think about it. But I need to fix all the issues you've reported before.
Is there anything else like throws an exception?
from sqfentity.
Thanks a lot!!!
from sqfentity.
I wrote new tickets. If I find something breaking I will report. Thanks again.
from sqfentity.
is it enough to put your compiled custom code as a string const into the constructor body of your table?
this is your custom method(s):
void setDefaultValues() {
... }
//end of sqfentity methods
// CUSTOM METHODS
String fullName()
{
return '$firstName $lastName';
}
// END CUSTOM METHODS
and your table model is here:
const tableCategory = SqfEntityTable(
tableName: 'person',
// declare fields
fields: [
SqfEntityField('firstName', DbType.text, formIsRequired: true),
SqfEntityField('lastName', DbType.bool, defaultValue: true),
....
],
customCodes: '''
String fullName()
{
return '\$firstName \$lastName';
}
''');
from sqfentity.
1- I added equalsOrNull keyword for queries
Example:
// this query lists only isActive=false
final productList = await Product().select().isActive.not.equals(true).toList();
// but this query lists isActive=false and isActive is null both
final productList = await Product().select().isActive.not.equalsOrNull(true).toList();
2- you can define customCodes property of your SqfEntityTable constant for ex:
const tablePerson = SqfEntityTable(
tableName: 'person',
primaryKeyName: 'id',
primaryKeyType: PrimaryKeyType.integer_auto_incremental,
fields: [
SqfEntityField('firstName', DbType.text),
SqfEntityField('lastName', DbType.text),
],
customCodes: '''
String fullName()
{
return '\$firstName \$lastName';
}
''');
from sqfentity.
Yes, this is all great. Just one suggestion... I think your parameter should be named customCode, not customCodes.
from sqfentity.
Alright.. 👍
from sqfentity.
Related Issues (20)
- Requirement of `tryParseDateTime` etc not mentioned in documentation HOT 7
- how to catch CRUD exception HOT 5
- Apparent infinite loop with many to many relationship and preload: true
- Fail to initialize on Windows
- Create table error
- toDropDownMenu Method HOT 1
- analyzer 5.0.0 HOT 1
- save() method doesn't update records HOT 1
- SQL Query execDataTable HOT 3
- `upsertAll()` fails to save results while `upsert()` will HOT 1
- Encrypt the rows in DB while inserting
- Multiple requests of creating/updading database/table
- modfiy DB password dynamically
- Relationship Exceptions and DateTime issues
- Support Dart 3/flutter 3.10 HOT 2
- Sqfentity
- How to handle db schema changes from old version to new version.
- Auto migrations do not drop removed columns
- add column And call initializeDB
- Cannot create a column name as "json"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqfentity.