Comments (1)
Sorry for the slow response. If you have something that already resembles a primary key in your data, the easiest way would be to reference that instead of an additional local ID.
For instance, you're also not referencing the product id key in the PartNumber
table, you're only storing its name. Similarly, if the part numbers where unique in each product line, you could use {partNumber, productLineName}
as a primary key of PartNumber
and only reference the part number in ProductLine.partNumbers
.
Without batches, you could also insert the part numbers first to get their id and then insert the product line afterwards:
Future<List<ProductLineCompanion>> createProductLines() async {
// ...
List<ProductLineCompanion> productLines = [];
for (var data in jsonData) {
var partNumberIds = <int>[];
for (var product in data.partNumbers) {
final partNumberCompanion = PartNumberCompanion.insert(
partNumber: product.partNumber,
orderable: product.orderable,
description: product.description,
productLineName: data.name,
);
final row = await into(partNumber).insert(partNumberCompanion);
partNumberIds.add(row);
}
final productLine = ProductLineCompanion.insert(
name: data.name,
partNumbers: PartNumberEntries(partNumberIds: partNumberIds),
);
productLines.add(productLine);
}
return productLines;
}
When inserting larger amounts of data, you can do this efficiently by wrapping createProductLines
in a transaction.
from drift.
Related Issues (20)
- Encryption documentation (for `encrypted_drift`) (`file is not a database`) HOT 4
- Database Connection Handler. HOT 2
- How to reference a Table which is in another package? HOT 5
- Cannot use a pre-existing sqlite db in drift web HOT 1
- Deadlock when running statements created outside of transaction in transaction HOT 3
- support table-valued function syntax HOT 2
- NoSuchMethodError: Class 'GeneratedColumn<int>' has no instance method 'count'. HOT 1
- Don't wrap exceptions in `DriftRemoteException` if not necessary
- "type 'Null' is not a subtype of type 'InterfaceElement' in type cast" during code generation HOT 2
- Provide `Comparable` expressions for postgres types HOT 2
- Usage without Row Models HOT 2
- Error when validating database schema in Flutter DevTools HOT 2
- Very weired query, both true or false can no t be get out HOT 2
- Simple count(*)? HOT 1
- The 'ie' suffix of the DataClass generated when executing build is automatically changed to 'y' HOT 1
- Implement Geopoly Interface HOT 1
- Incorrect Variable Bindings in Postgres Transactions HOT 4
- SqliteException(261): while executing, database is locked, database is locked (code 261) Causing statement: PRAGMA wal_checkpoint(PASSIVE);PRAGMA busy_timeout = 5000;PRAGMA journal_size_limit = 6144000;PRAGMA synchronous = normal;PRAGMA journal_mode = WAL; HOT 3
- `FOREIGN KEY` defined in the `.drift` file, in between the other column line then typed-class not getting generated... HOT 1
- Migration issues with Firefox HOT 1
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 drift.