dflourusso / expo-sqlite-orm

Expo SQLite ORM
132 stars 34 forks source link

find() and query() returns differents results #25

Closed allandiego closed 3 years ago

allandiego commented 4 years ago

Hello,

Im facing a strange behavior, find() and query() functions returns differents results:

QUERY

const cellsCountersList = await CellCounter.query({
        where: { id_eq: 1 },
        page: 1,
        limit: 10,
      });
      console.log(cellsCountersList);
/*
Array [
  Object {
    "baso_count": 1,
    "baso_percent": 10,
    "created_at": null,
    "description": "",
    "eos_count": 1,
    "eos_percent": 10,
    "id": 1,
    "is_sent": false,
    "lym_count": 1,
    "lym_percent": 10,
    "mono_count": 2,
    "mono_percent": 20,
    "nrbc_count": 1,
    "nrbc_percent": 10,
    "other1_count": 1,
    "other1_percent": 10,
    "other2_count": null,
    "other2_percent": null,
    "other3_count": null,
    "other3_percent": null,
    "patient_name": "test",
    "reference_id": 2587,
    "ret_count": 0,
    "ret_percent": 0,
    "seg_count": 2,
    "seg_percent": 20,
    "sent_at": null,
    "st_count": 1,
    "st_percent": 10,
    "total_count": 10,
    "updated_at": null,
  },
]
*/

FIND / CREATE


    const response = await CellCounter.create(data);
    console.log(response);

      const cellsCountersList2 = await CellCounter.find(1);
      console.log(cellsCountersList2);
      /*
returns the correct data filled with default() from model
        CellCounter {
  "baso_count": 1,
  "baso_percent": 10,
  "created_at": 1581426939311,
  "description": null,
  "eos_count": 1,
  "eos_percent": 10,
  "id": 1,
  "is_sent": false,
  "lym_count": 1,
  "lym_percent": 10,
  "mono_count": 2,
  "mono_percent": 20,
  "nrbc_count": 1,
  "nrbc_percent": 10,
  "other1_count": 1,
  "other1_percent": 10,
  "other2_count": 0,
  "other2_percent": 0,
  "other3_count": 0,
  "other3_percent": 0,
  "patient_name": "test",
  "reference_id": 2587,
  "ret_count": 0,
  "ret_percent": 0,
  "seg_count": 2,
  "seg_percent": 20,
  "sent_at": null,
  "st_count": 1,
  "st_percent": 10,
  "total_count": 10,
  "updated_at": 1581426939311,
}
       */

MODEL

export default class CellCounter extends BaseModel {
  static get database() {
    return async () => SQLite.openDatabase('database.db');
  }

  static get tableName() {
    return 'cells_counters';
  }

  static get columnMapping() {
    return {
      id: { type: types.INTEGER, primary_key: true },
      reference_id: { type: types.INTEGER, unique: true },
      patient_name: { type: types.TEXT, not_null: true },
      description: { type: types.TEXT },
      is_sent: { type: types.BOOLEAN, default: () => false },
      sent_at: { type: types.INTEGER },

      total_count: { type: types.NUMERIC, default: () => 0 },

      seg_count: { type: types.NUMERIC, default: () => 0 },
      seg_percent: { type: types.NUMERIC, default: () => 0 },

      st_count: { type: types.NUMERIC, default: () => 0 },
      st_percent: { type: types.NUMERIC, default: () => 0 },

      lym_count: { type: types.NUMERIC, default: () => 0 },
      lym_percent: { type: types.NUMERIC, default: () => 0 },

      mono_count: { type: types.NUMERIC, default: () => 0 },
      mono_percent: { type: types.NUMERIC, default: () => 0 },

      eos_count: { type: types.NUMERIC, default: () => 0 },
      eos_percent: { type: types.NUMERIC, default: () => 0 },

      baso_count: { type: types.NUMERIC, default: () => 0 },
      baso_percent: { type: types.NUMERIC, default: () => 0 },

      nrbc_count: { type: types.NUMERIC, default: () => 0 },
      nrbc_percent: { type: types.NUMERIC, default: () => 0 },

      ret_count: { type: types.NUMERIC, default: () => 0 },
      ret_percent: { type: types.NUMERIC, default: () => 0 },

      other1_count: { type: types.NUMERIC, default: () => 0 },
      other1_percent: { type: types.NUMERIC, default: () => 0 },

      other2_count: { type: types.NUMERIC, default: () => 0 },
      other2_percent: { type: types.NUMERIC, default: () => 0 },

      other3_count: { type: types.NUMERIC, default: () => 0 },
      other3_percent: { type: types.NUMERIC, default: () => 0 },

      created_at: { type: types.INTEGER, default: () => Date.now() },
      updated_at: { type: types.INTEGER, default: () => Date.now() },
    };
  }
}