Comments (3)
Hey @mrmeyers99 thanks for using Brick.
Brick does use an internal primary key, and that key should not be managed by application code. This key is also not transmitted to Rest. It's a SQLite-only key. There is one caveat on where your application code should access this primaryKey
: when the instance is being copied, like in the MaterialTheme TextTheme sense:
Pizza copyWith({List<String> toppings}) {
return Pizza(
toppings: toppings ?? this.toppings,
)..primaryKey = primaryKey;
}
Regarding identifying data between your API and your client, that's a little less clear since APIs vary. The API should transmit a key that identifies that data - this could be an autoincrement key from a database, or it could be a generated ID. Brick has an annotation @Sqlite(unique: true)
for associating these foreign identifiers to client-side data (and adding an index to the column in your API to ensure uniqueness/quick lookups). To avoid conflicts with identifiers, I'd recommend the UUID pacakge which handles ID generation with different protocols (the differences are important and I'd recommend doing some research to fit your needs; v1 is best for many clients but v4 is more standard).
If you're still structuring your API, I'd also recommend writing endpoints that are exclusive to their domain. For example, if you want pizzas for customers, your endpoint would be /pizzas?by_customer_id=<id>
. If you want customers, you use /customers
and the payload includes nested pizza data (pizzas: [{}]
) OR an array of IDs (pizzas: []
). Brick supports both so long as the receiving endpoint is configured.
in your endpoint
body, I'd also recommend accessing instance
when making mutating calls:
if (query.action == QueryAction.upsert && instance != null) {
// or return "/pizzas?by_customer_id=${instance.customer.id}"
return "/customers/${instance.customer.id}/pizzas";
}
And you're right that documentation is missing on this. Where did you look to find this, or rather, where did you expect this documentation to live? I'd like to add it there.
from brick.
Thanks for the suggestion. I think you're right, UUID's are probably the best bet for my use case.
As far as documentation, I think a section between Providers and Repositories
and Learn
that talks about the server side considerations would be nice. Also, maybe more complete server side code in the example project that shows creating a pizza would help.
from brick.
Resolving in #117
from brick.
Related Issues (20)
- Row query HOT 3
- GraphQL support? HOT 2
- Thank you! HOT 1
- How to convert a model field to a small letter in a Query? HOT 2
- build_runner build error HOT 2
- Update version HOT 1
- Bug : broken "Full documentation" link in README.md HOT 1
- Analyzer version conflict with many libs HOT 1
- **Migrating to Brick 2 from Brick 1**
- Can't generate anything since update to v2 HOT 5
- Current state of this project? HOT 8
- Is @ConnectOfflineFirstWithRest() part of Brick 2 or Brick 1? HOT 2
- Question - Hive/Isar local storage support? HOT 1
- No Support for Realm - A More Fully-Featured DB for Resource Constrained Environments HOT 4
- Outdated documentation and examples HOT 4
- Get 'is not a Dart library. It may be a part file or a file without Dart source code.' error on run build runner HOT 12
- Need to run build_runner twice for correct schema.g.dart generation HOT 1
- Discussion: cache busting HOT 4
- **Migrating to Brick 3 from Brick 2**
- Casting issue with latest example code. HOT 2
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 brick.