Failed to insert mockup data
fourmatrix opened this issue · 1 comments
fourmatrix commented
Refer to tutorial https://developers.sap.com/tutorials/cap-cloudsdk-1-mock-service.html,
I tried to mock hana service, but I change the location and content of server.js, I moved server.js to ./srv folder, and use 'served' event callback to insert mockup data, if failed with error:
[ERROR] SQLITE_ERROR: no such table: API_BUSINESS_PARTNER_A_BusinessPartnerAddressType
the content of server.js is:
"use strict";
const cds = require("@sap/cds");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");
cds.on("bootstrap", app => app.use(proxy()));
module.exports = cds.server;
cds.once("served", async (csn)=>{
// Seed with sample data
// cds.deploy('srv').to('sqlite::memory:',{primary:true}) .then (async db => {
const db = await cds.connect.to("db"); //cds.db; //
const { A_BusinessPartnerAddress: Addresses } = db.entities('API_BUSINESS_PARTNER')
console.log('Adding sample data...')
console.log(Addresses+'');
const addresses = db.run (INSERT.into(Addresses+'').entries(
{
BusinessPartner: '1003764',
AddressID: '28238',
CityName: 'Walldorf',
StreetName: 'Dietmar-Hopp-Allee'
},
{
BusinessPartner: '1003765',
AddressID: '28241',
CityName: 'Palo Alto',
StreetName: 'Hillview Avenue'
},
{
BusinessPartner: '1003766',
AddressID: '28244',
CityName: 'Hallbergmoos',
StreetName: 'Zeppelinstraße'
},
{
BusinessPartner: '1003767',
AddressID: '28247',
CityName: 'Potsdam',
StreetName: 'Konrad-Zuse-Ring'
}
))
await Promise.all ([addresses])
console.log('Adding sample data... success')
// }) .catch (console.error)
})