אני מנסה להוסיף נתונים למסד נתונים של Redis שממנו העתקתי: https://redis.io/docs/stack/get-started/tutorials/stack-node זו הסכמה שלי:
import { Entity, Schema } from 'redis-om'
import client from './client.js'
import { router as person_router, router } from '../routers/person_router.js'
/* our entity */
class Person extends Entity {}
const personSchema = new Schema(
Person, {
firstName: {
type: "string",
},
lastName: {
type: "string",
},
age: {
type: "text",
},
pulse_at_rest: { //דופק במנוחה
type: "text",
},
background_diseases_and_medical_limitations: { //מחלות_רקע ומגבלות_רפואיות
type: "string",
},
Working: { //עבודה
type: "string",
},
password: {
type: "string",
},
Preferred_training_time: {//זמן_אימון_מועדף
type: "string",
},
the_duration_of_the_training: {//משך הריצה
type: "text",
},
goal: { //מטרה
type: "string",
},
gender: {//מין
type: "text",
},
height: {
type: "text",
},
Sports_background: {//רקע_ספורט
type: "string",
},
},
)
/* use the client to create a Repository just for Persons */
export const personRepository = client.fetchRepository(personSchema);
/* create the index for Person */
personRepository.createIndex().then(data=> {console.log(data)}).catch(err => {console.log("err", err)})
export default Person
והנה אני משתמש בו:
import { createClient } from 'redis-om';
import { Client } from 'redis-om';
import { personRepository } from './person';
/* pulls the Redis URL from .env */
const url = process.env.REDIS_URL;
/* create a connection to Redis with redis-om */
export const connection = createClient({ url });
connection.connect();
/* create a Client and bind it to the redis-om connection */
const client = new Client().use(connection);
async function fetchData(id) {
const person = await personRepository.fetch(id);
console.log(person); // Log the person data
return person;
// Use the person data here
}
(async () => {
const id = "123455";
const person = await fetchData(id);
person.location = { longitude, latitude };
person.locationUpdated = locationUpdated;
await personRepository.save(person);
let keyName = `${person.keyName}:locationHistory`;
await connection.xAdd(keyName, '*', person.location);
})();
export default client;
אבל כשאני מייבא את הקובץ לקובץ הראשי:
import { router as personRouter } from './routers/person_router.js'
אני מקבל
node:internal/errors:490 ErrorCaptureStackTrace(err); ^
שגיאה [ERR_MODULE_NOT_FOUND]: לא ניתן למצוא את המודול 'C:\Users\hodaya\Downloads\express-redis-om-workshop-main\express-redis-om-workshop-main\om\person' מיובא מ-C:\Users\hodaya \Downloads\express-redis-om-workshop-main\express-redis-om-workshop-main\routers\person_router.js ב-NodeError חדש (צומת:internal/errors:399:5) ב-finalizeResolution (צומת:internal/modules) /esm/resolve:326:11) ב-modulResolve (node:internal/modules/esm/resolve:945:10) ב-defaultResolve (node:internal/modules/esm/resolve:1153:11) ב-nextResolve (node:internal/ modules/esm/loader:163:28) ב-ESMLoader.resolve (node:internal/modules/esm/loader:838:30) ב-ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) ב-ModuleWrap . (node:internal/modules/esm/module_job:77:40) בקישור (node:internal/modules/esm/module_job:76:36) { code: 'ERR_MODULE_NOT_FOUND' }
מישהו יודע אולי מה הבעיה כאן? ואיך אפשר לתקן את זה?
import { Entity, Schema } from 'redis-om'
import client from './client.js'
import { router as person_router, router } from '../routers/person_router.js'
/* our entity */
class Person extends Entity {}
const personSchema = new Schema(
Person, {
firstName: {
type: "string",
},
lastName: {
type: "string",
},
age: {
type: "text",
},
pulse_at_rest: { //דופק במנוחה
type: "text",
},
background_diseases_and_medical_limitations: { //מחלות_רקע ומגבלות_רפואיות
type: "string",
},
Working: { //עבודה
type: "string",
},
password: {
type: "string",
},
Preferred_training_time: {//זמן_אימון_מועדף
type: "string",
},
the_duration_of_the_training: {//משך הריצה
type: "text",
},
goal: { //מטרה
type: "string",
},
gender: {//מין
type: "text",
},
height: {
type: "text",
},
Sports_background: {//רקע_ספורט
type: "string",
},
},
)
/* use the client to create a Repository just for Persons */
export const personRepository = client.fetchRepository(personSchema);
/* create the index for Person */
personRepository.createIndex().then(data=> {console.log(data)}).catch(err => {console.log("err", err)})
export default Person
והנה אני משתמש בו:
import { createClient } from 'redis-om';
import { Client } from 'redis-om';
import { personRepository } from './person';
/* pulls the Redis URL from .env */
const url = process.env.REDIS_URL;
/* create a connection to Redis with redis-om */
export const connection = createClient({ url });
connection.connect();
/* create a Client and bind it to the redis-om connection */
const client = new Client().use(connection);
async function fetchData(id) {
const person = await personRepository.fetch(id);
console.log(person); // Log the person data
return person;
// Use the person data here
}
(async () => {
const id = "123455";
const person = await fetchData(id);
person.location = { longitude, latitude };
person.locationUpdated = locationUpdated;
await personRepository.save(person);
let keyName = `${person.keyName}:locationHistory`;
await connection.xAdd(keyName, '*', person.location);
})();
export default client;
אבל כשאני מייבא את הקובץ לקובץ הראשי:
import { router as personRouter } from './routers/person_router.js'
אני מקבל
node:internal/errors:490 ErrorCaptureStackTrace(err); ^
שגיאה [ERR_MODULE_NOT_FOUND]: לא ניתן למצוא את המודול 'C:\Users\hodaya\Downloads\express-redis-om-workshop-main\express-redis-om-workshop-main\om\person' מיובא מ-C:\Users\hodaya \Downloads\express-redis-om-workshop-main\express-redis-om-workshop-main\routers\person_router.js ב-NodeError חדש (צומת:internal/errors:399:5) ב-finalizeResolution (צומת:internal/modules) /esm/resolve:326:11) ב-modulResolve (node:internal/modules/esm/resolve:945:10) ב-defaultResolve (node:internal/modules/esm/resolve:1153:11) ב-nextResolve (node:internal/ modules/esm/loader:163:28) ב-ESMLoader.resolve (node:internal/modules/esm/loader:838:30) ב-ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) ב-ModuleWrap . (node:internal/modules/esm/module_job:77:40) בקישור (node:internal/modules/esm/module_job:76:36) { code: 'ERR_MODULE_NOT_FOUND' }
מישהו יודע אולי מה הבעיה כאן? ואיך אפשר לתקן את זה?