hey everyone! Hope you had a lovely weekend. Does...
# orm-help
l
hey everyone! Hope you had a lovely weekend. Does anyone know a way to query for model 1 before a timestamp up to another timestamp? My example is for IoT states which are sent to a large table and i would like to get the states between two dates, but since the timestamps are only for the start of the state, i end up always loosing the first state. I have a weird workaround like this:
Copy code
const after = prisma.deviceEvent
          .findMany({
            where: {
              device_id: device_id || undefined,
              timestamp: {
                gte: args.start_date || undefined,
                lt: args.end_date || undefined,
              },
            },
          })

const before = prisma.deviceEvent
          .findFirst({
            where: {
              device_id: device_id || undefined,
              timestamp: {
                lte: args.start_date || undefined,
              },
            },
          })

return [before, ...after];
but this doesnt feel very elegant and was hoping to find some
before
or
after
param i could use in prisma. Any suggestions?
✅ 1
n
Hey Lloyd 👋 Using gt and lt filter operations is currently the only way to get records between two dates (timestamps) which you are doing at the moment.
l
thanks for the reply. Little sad that there isnt a cleaner way to do this 😞 but my hack around works for now