Here we focus on two important atom operations: read and select

read

Frontend

this.$api.post('/a/base/atom/read', {
  key: { atomId, itemId },
}).then(item => {
  console.log(item);
});

Backend

const user = this.ctx.user.op;
const item = await this.ctx.meta.atom.read({
  key: { atomId, itemId },
  user,
});

select

Frontend

this.$api.post('/a/base/atom/select', {
  atomClass: {
    id,
    module,
    atomClassName,
  },
  options: { 
    where: {
      ['a.atomName']: { op: 'like', val: 'atomName' }
    },
    orders: [
      [ 'a.updatedAt', 'desc' ],
    ],
    page: { index: 0, size: 10 },
  },
}).then(data => {
  console.log(data.list, data.index, data.finished);
});

Return Result

Name Description
data.list atom list
data.index paging index for next page
data.finished Whether the data has been acquired completely. If so, you won’t get the next page any more

Parameters

Name Allowed to be null Description
atomClass yes Atom Class
options.where yes query criteria
options.orders yes order
options.page.index no paging index
options.page.size yes paging size

List of Join Tables

The implementation principle of atom select operation is: combine SQL statements according to the parameters submitted by users, which will combine some tables to obtain the information users want

Table Name Table Alias Description
aAtom a table of aAtom
aAtomClass b table of aAtomClass
For Example: testPartyView f table/view of business table

where clause

The where clause in EggBornJS is similar to the where clause in EggJS, such as:

where: { atomName: 'test', atomFlag: 1 },

In addition, the where clause in EggBornJS also provides enhanced operations for building more complex conditions, such as:

operation: in
where: { 
  'a.id': { 
    op: 'in', val: [ 1, 2, 3 ],
  },
},
operation: like
where: { 
  'a.atomName': { 
    op: 'like', val: 'test', 
  },
},
operation: likeLeft
where: { 
  'a.atomName': { 
    op: 'likeLeft', val: 'test', 
  }, 
},
operation: likeRight
where: { 
  'a.atomName': { 
    op: 'likeRight', val: 'test', 
  },
},

orders

The sorting usage of orders in EggBornJS is the same as that of orders in EggJS, such as:

orders: [
  [ 'a.updatedAt', 'desc' ],
],

page

EggBornJS adds the page feature, which generates limitand offset in SQL clause through the combination of page index and page size

Generally speaking, the frontend does not need to pass page.size. Instead, the backend fills in this value uniformly. You can override the default value of page.size in the config file of the project, as follows:

src/backend/config/config.default.js

// modules
config.modules = {
  'a-base': {
    pageSize: 20,
  },
};

Backend

const user = this.ctx.user.op;
const items = await this.ctx.meta.atom.select({
  atomClass,
  options: { 
    where,
    orders,
    page,
  },
  user,
});