Coder Social home page Coder Social logo

Comments (11)

hhtokpinar avatar hhtokpinar commented on July 18, 2024

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.

boskokg avatar boskokg commented on July 18, 2024

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.

hhtokpinar avatar hhtokpinar commented on July 18, 2024

Ok. My job is already with the async side!
So do you have any suggestions? :-]

from sqfentity.

boskokg avatar boskokg commented on July 18, 2024

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.

hhtokpinar avatar hhtokpinar commented on July 18, 2024

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.

boskokg avatar boskokg commented on July 18, 2024

Thanks a lot!!!

from sqfentity.

boskokg avatar boskokg commented on July 18, 2024

I wrote new tickets. If I find something breaking I will report. Thanks again.

from sqfentity.

hhtokpinar avatar hhtokpinar commented on July 18, 2024

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.

hhtokpinar avatar hhtokpinar commented on July 18, 2024

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.

boskokg avatar boskokg commented on July 18, 2024

Yes, this is all great. Just one suggestion... I think your parameter should be named customCode, not customCodes.

from sqfentity.

hhtokpinar avatar hhtokpinar commented on July 18, 2024

Alright.. 👍

from sqfentity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.