zyxw59 / accounting

Multi-user accounting software
MIT License
0 stars 0 forks source link

Query API #2

Open zyxw59 opened 1 year ago

zyxw59 commented 1 year ago

I need an API on the Collection trait for searching for an object on field(s) other than id.

For the design of this API, I want to balance

zyxw59 commented 1 year ago

For typedness, I could have each queryable type provide an enum of all its queryable fields — e.g. for Account it'd be something like

pub enum AccountQuery {
    Name(String),
    Description(String),
}

(and then maybe there's also a type for combining queries and applying modifiers like inequalities)

But then translating all of those enums to (e.g.) mongodb queries is a lot of work

zyxw59 commented 1 year ago

ooh, for Transactions this gets hairier. A transaction has a Map<Id<Account>, Amount>, which has many possible queries one could imagine:

zyxw59 commented 1 year ago

and then there's even more complication when adding comparators other than = into the mix — for equals, it's fine to translate "transaction involves account 123 with amount $4.56`" into

{ amounts: { $eq: { account: 123, value: 4.56 } } }

but if we want to search on the account and the value, with a different comparator (e.g. <), it needs to be

{ amounts: { account: 123, value: { $lt: 4.56 } } }

and I don't know of a good way to express this in the general case