Custom Entity Store : query result empty

Hi guys,

I play with Custom Entity Store, no error, but nothing in the Storage, nothing in the query :frowning:

Some parts of my code :

Manifest
Btw : i use “issue”, “test1” is the previous test

type or paste code   storage:
    entities:
      - name: issue
        attributes:
          id:
            type: string
          summary:
            type: string
          status:
            type: string
          createdDate:
            type: string
        indexes:
          - status
          - createdDate
          - name: "by-status"
            range:
              - status
            partition:
              - status
          - name: "by-status-createdDate"
            range:
              - createdDate
            partition:
              - status
      - name: test1
        attributes:
          component:
            type: string
          product:
            type: string
          scope:
            type: string
          team:
            type: string
          bu:
            type: string
        indexes:
          - name: "by-component"
            range:
              - component
            partition:
              - component
          - name: "by-product"
            range:
              - product
            partition:
              - product
          - name: "by-scope"
            range:
              - scope
            partition:
              - scope
          - name: "by-team"
            range:
              - team
            partition:
              - team
          - name: "by-bu"
            range:
              - bu
            partition:
              - buhere

The webtrigger async

...
const getIssueById = async (id) => {
	return await storage.entity("issue").get(id);
};

const getIssues = async (status) => {
	const results = await storage.entity("issue").query()
		.index("by-status", {
			partition: ["status"]
		})
		.limit(2)
		.getMany();
};

const getIssuesByStatus = async (status) => {
	const results = await storage.entity("issue").query()
		.index("by-status", {
			partition: ["status"]
		})
		.where(WhereConditions.equalsTo('Close'))
		.limit(2)
		.getMany();
	return results;
};

exports.runAsync = async (request) => {
	try {
		const issue1 = {
			id: 'ISSUE-120',
			summary: 'Issue summary',
			status: 'Close',
			createdDate: '2024-07-18'
		};

		await storage.entity("issue").set(issue1.id, issue1);

		const issue2 = {
			id: 'ISSUE-121',
			summary: 'Issue summary',
			status: 'Close',
			createdDate: '2024-07-18'
		};

		await storage.entity("issue").set(issue2.id, issue2);

		const issue3 = {
			id: 'ISSUE-122',
			summary: 'Issue summary',
			status: 'Close',
			createdDate: '2024-07-18'
		};

		await storage.entity("issue").set(issue3.id, issue3);

		const issue4 = {
			id: 'ISSUE-123',
			summary: 'Issue summary',
			status: 'Close',
			createdDate: '2024-07-18'
		};

		await storage.entity("issue").set(issue4.id, issue4);

		const issue1FromStorage = await getIssueById('ISSUE-121');
		console.log("getIssueById: " + JSON.stringify(issue1FromStorage));

		const issue3FromStorage = await getIssueById('ISSUE-123');
		console.log("getIssueById: " + JSON.stringify(issue3FromStorage));

		const issues = await getIssues();
		console.log("issues: " + JSON.stringify(issues));

		const issuesByStatus = await getIssuesByStatus('Open');
		console.log("openIssues: " + JSON.stringify(issuesByStatus));
....

Storage is empty. Is there an other Storage for Custom Entity? and this one is dedicated for simple key/value?

My Logs

Looks like the storage.set is OK, i can Get the value even there is nothing is the Developer Storage.
My query test doesn’t bug, but result is empty.

Any ideas?

Regards.

BTW : my package.json

{
“dependencies”: {
@forge/api”: “^3.8.1”
}
}

Yes, this is true.

Regarding the query being empty, if you have uninstalled and reinstalled your app, it could be because of this bug: https://jira.atlassian.com/browse/ECO-313 At least the part for by status.

Custom Entity is not stable :frowning:
In my case, no work around like it’s describe in the issue, there is no nextCursor.
openIssues: {"results":[],"nextCursor":null}

Hope it will be fix and stable. Custom Entity are cool

Hi @Denis2, data stored as part of Custom Entities can not be viewed in the developer console and this is a known limitation of the platform at the moment. Developer console will only show data being stored as part of key-value store.

Regarding no data while querying, I think there is an issue with the query itself -

const getIssues = async (status) => {
	const results = await storage.entity("issue").query()
		.index("by-status", {
			partition: ["status"]
		})
		.limit(2)
		.getMany();
};

In the above snippet, you are passing a hard coded value status while it is expecting a value for status.

Do you mind giving the below snippet a try?

const getIssues = async (status) => {
	const results = await storage.entity("issue").query()
		.index("by-status", {
			partition: [status]
		})
		.limit(2)
		.getMany();
};

For more queries example, check our docs here.

2 Likes

Doesn’t work, but maybe you right, cause, i tried doc example and it works.

Manifest

  storage:
    entities:
      - name: employee
        attributes:
            surname:
              type: string
            age:
              type: integer
            employmentyear:
              type: integer
            gender:
              type: string
            nationality:
              type: string
        indexes:
            - surname
            - employmentyear
            - name: by-age
              range:
                - age
            - name: by-age-per-gender
              partition:
                - gender
              range:
                - age

code

		const employee1 = {
			surname: 'employee1',
			age: 10,
			employmentyear: 2001,
			gender: 'male',
			nationality: 'FR'
		};
		await storage.entity("employee").set(employee1.surname, employee1);

		const employee2 = {
			surname: 'employee2',
			age: 20,
			employmentyear: 2002,
			gender: 'male',
			nationality: 'FR'
		};
		await storage.entity("employee").set(employee2.surname, employee2);

		const employee3 = {
			surname: 'employee3',
			age: 30,
			employmentyear: 2003,
			gender: 'male',
			nationality: 'Australian'
		};
		await storage.entity("employee").set(employee3.surname, employee3);

		const employee4 = {
			surname: 'employee4',
			age: 40,
			employmentyear: 2004,
			gender: 'female',
			nationality: 'FR'
		};
		await storage.entity("employee").set(employee4.surname, employee4);

		const employee5 = {
			surname: 'employee5',
			age: 50,
			employmentyear: 2005,
			gender: 'female',
			nationality: 'FR'
		};
		await storage.entity("employee").set(employee5.surname, employee5);

		const employee6 = {
			surname: 'employee6',
			age: 60,
			employmentyear: 2006,
			gender: 'female',
			nationality: 'Australian'
		};
		await storage.entity("employee").set(employee6.surname, employee6);

		const employee7 = {
			surname: 'employee7',
			age: 60,
			employmentyear: 2021,
			gender: 'female',
			nationality: 'Australian'
		};
		await storage.entity("employee").set(employee7.surname, employee7);

		const employee1FromStorage = await storage.entity("employee").get("employee1");
		console.log("getEmployeeById: " + JSON.stringify(employee1FromStorage));

		const employee4FromStorage = await storage.entity("employee").get("employee4");
		console.log("getEmployeeById: " + JSON.stringify(employee4FromStorage));

		const results1 = await storage
			.entity("employee")
			.query()
			.index("surname")
			.getMany();
		console.log("results1: " + JSON.stringify(results1));

		const results2 = await storage
			.entity("employee")
			.query()
			.index("by-age")
			.where(WhereConditions.isGreaterThan(30))
			.sort(SortOrder.DESC)
			.getMany();
		console.log("results2: " + JSON.stringify(results2));

		const results3 = await storage
			.entity("employee")
			.query()
			.index("by-age-per-gender", {
				partition: ["female"]
			})
			.getMany();
		console.log("results3: " + JSON.stringify(results3));

		const results4 = await storage
			.entity("employee")
			.query()
			.index("by-age-per-gender", {
				partition: ["female"]
			})
			.where(WhereConditions.isGreaterThan(30))
			.getMany();
		console.log("results4: " + JSON.stringify(results4));

		const results5 = await storage
			.entity("employee")
			.query()
			.index("by-age-per-gender", {
				partition: ["female"]
			})
			.where(WhereConditions.isGreaterThan(30))
			.andFilter("employmentyear",
				FilterConditions.isGreaterThan(2020))
			.andFilter("nationality",
				FilterConditions.equalsTo("Australian"))
			.getMany();
		console.log("results5: " + JSON.stringify(results5));

results

1 Like

Hi @Denis2 just checking if you are able to sort out the issue with queries from your original request or do you need more help here?

Thank you @MuditJuneja, i found a way to get results and sometimes with the hack to get results with cursor

1 Like