Coder Social home page Coder Social logo

Query Argument for Get Method about brick HOT 7 CLOSED

getdutchie avatar getdutchie commented on July 17, 2024
Query Argument for Get Method

from brick.

Comments (7)

tshedor avatar tshedor commented on July 17, 2024

@SubutaDan no, geting an instance is not supported because, well, you already have that instance.

If you're trying to fetch the latest data of something, you can do a query based on Brick's internal primary key:

import 'package:brick_sqlite_abstract/db.dart';

final repositoryInstances = Repository().get<MyModelType>(query: Query.where(InsertTable.PRIMARY_KEY_FIELD, myModelInstance.primaryKey, limit1: true);
final hydratedInstance = (repositoryInstances?.isNotEmpty ?? false) ? repositoryInstances.first : null;

from brick.

SubutaDan avatar SubutaDan commented on July 17, 2024

Thanks, @tshedor , but my question is slightly different. Sorry I wasn't more clear.

Is there a way to pass a URL query string argument to a get method:

https://myapiserver.com/cats?name=${i_want-to_pass_in_this_value}

If the method is a PUT or a POST I can use an instance field in the query string but I don''t know how to pass a value for a GET as there is no instance.

-Dan

from brick.

tshedor avatar tshedor commented on July 17, 2024

@SubutaDan

Ah, I got you. Yes. endpoint: uses an instance and query as its parameters.

@ConnectOfflineFirstWithRest(
  restConfig: RestSerializable(
    endpoint: r'''{
      if (query?.action == QueryAction.get && query?.where != null) {
        final name = Where.firstByField('name', query.where)?.value;
        if (name != null) return "/cats?name=${name}";
      }

      return "/cats";
    }''';
  )
)
class Cat extends OfflineFirstWithRestModel {}

And then you'd invoke this:

await Repository().get<Cat>(query: Query.where('name').isExactly('Old Deuteronomy'));

Of course, it's up to you on how to handle the query operator, so isExactly, contains, notEqual will all be the same with the above implementation of endpoint:.

from brick.

SubutaDan avatar SubutaDan commented on July 17, 2024

from brick.

tshedor avatar tshedor commented on July 17, 2024

Hi @SubutaDan could you please give this mixin a try?

from brick.

SubutaDan avatar SubutaDan commented on July 17, 2024

from brick.

tshedor avatar tshedor commented on July 17, 2024

Closing this issue; confirmed working

from brick.

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.