dflourusso / expo-sqlite-orm

Expo SQLite ORM
139 stars 34 forks source link

column validations are too strict #51

Open realjjaveweb opened 2 years ago

realjjaveweb commented 2 years ago

The column validation is too strict in what can go in and out.

Out:

await SomeModel.query({
    columns: 'COUNT(*)',
});

This returns EMPTY results, because obviously there is no known column name, but if there's an "id" column on the model, this works

await SomeModel.query({
    columns: 'COUNT(*) as id',
});

In If there are data missing on save, they are added anyways, but usually during update, you just want to update some columns, I would expect from .save() when primary key is present, just update columns available.

eznix86 commented 8 months ago

I think it should remain strict, instead we should have another function similar to prisma:

https://www.prisma.io/docs/orm/prisma-client/queries/aggregation-grouping-summarizing

await SomeModel.aggregate({
  $avg: {
    age: true,
  },
  $count: {
    age: true,
  },
})

Then instead of returning an object of the model, it returns an object of type Aggregate, with avg, and count attributes I talked about new key words there: #66