Comments (13)
Good stuff, thanks Michael, I'll have a look at this as soon as I can and ping you back if any issues
from dynamodb-onetable.
Good spelunking!
We're prototyping the fetch
method and exploring different options.
The alternative is: to use queryItems and groupByType as described in the README. We are exploring a cleaner way to read item collections using fetch.
Can you share your final .d.ts type definition?
from dynamodb-onetable.
Thanks for introducing me to a new word!
I didn't do anything with the .d.ts file, I just did a horrid cast to any:
items = await table.fetch(["User", "UserProfile"], {pk: `User:${id}`}) as any // error in types file
const users: UserType[] = items.User
const profiles: UserProfileType[] = items.UserProfile
from dynamodb-onetable.
We're still not quite ready to cement the API for fetch
. All ideas are welcome.
I'll get the .d.ts type fixed so you can experiment without the cast.
from dynamodb-onetable.
Perfect, many thanks.
Re the groupByType you mentioned, the README has this:
items = db.groupByType(items)
... but doesn't mention what "db" is? (Perhaps I'm being a bit dense here!)
from dynamodb-onetable.
We use db
sometimes for table
. It is a Table instance.
I'll fix the doc for that.
from dynamodb-onetable.
Just pushed to the REPO:
Added a type for fetch() and groupByType to Table.d.ts.
export type EntityGroup = {
[key: string]: AnyEntity
};
fetch(models: string[], properties: OneProperties, params?: OneParams): Promise<EntityGroup>;
groupByType(items: AnyEntity[]): EntityGroup;
And added a test/typescript-tennant.ts which does some basic exercise of the fetch API.
Though still not documented (fetch), here is the usage:
let collection = await table.fetch(['Account', 'User'], {pk: `account#${account.id}`})
You give a list of model types and the PK. Fetch has an implicit params.parse == true.
Returns similar to groupByType.
from dynamodb-onetable.
Fixed in 1.5.5.
Please give some feedback about the API. I'd like to settle on this and document it.
from dynamodb-onetable.
I'll keep this issue open until fetch is released fully.
from dynamodb-onetable.
Apologies Michael, I've been pulled onto something else briefly, I'll ping you back about this asap
from dynamodb-onetable.
Hey, so with the change to table.fetch
... if you key into the EntityGroup
the .d.ts says we get a single AnyEntity
value, but in reality we get AnyEntity[]
don't we?
As far as the fetch api itself goes it is useful, for sure. I can't help wondering whether we could get stronger typing. E.g. rather than keying into a collection by string (type name) could we key by model - i.e. Model<T>
- with the value being T[]
? May not be possible, I haven't delved into the code.
Cheers!
from dynamodb-onetable.
Understand. You would need to iterate the models first parameter.
Alternatively we could do something like:
let collection = await fetch<User, Account>(['User', 'Account'], {pk})
Otherwise, you would need to iterate the models array and construct type types from that. Not sure if TypeScript can enumerate arrays like we do when iterating the schema to create the model types.
from dynamodb-onetable.
We're going to document the current implementation for now.
from dynamodb-onetable.
Related Issues (20)
- params.fields are not respected when using table.getItem() or table.queryItems()
- Metrics.d.ts should not include function interfaces declared as 'async' HOT 7
- Improve: Prohibit the removal of nested object required fields. HOT 1
- Feature: Across entities query HOT 3
- Empty strings are filtered out HOT 2
- Cannot resolve type when ESM HOT 3
- Compound global index not updated if only 1 of 2 properties passed to the update function HOT 1
- Updating unique template field does not remove unique record HOT 2
- "CredentialsProviderError: The SSO session associated with this profile has expired" in "overview" sample... HOT 2
- Create method does not create the sort key if one attribute is undefined HOT 4
- Connecting OneTable to a local dynamodb instance
- Support for Mapped Types HOT 3
- Please Help: Update Problem (referenced attribute) HOT 3
- OneSchema type for getCurrentSchema() not set HOT 2
- Update operation does not remove object from array HOT 1
- Help: retrieving items by GSI1 HOT 1
- nested props are not getting mapped correctly with map attribute
- Getting error while update on object that contains undefined attribute value in it. HOT 2
- Cannot Transparently Pass On JSON String From Previously Unncrypted Field HOT 1
- queryItems requires { hidden:true } to support groupByType for AWS SDK v3 HOT 4
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 dynamodb-onetable.