Я не уверен, что не так, я пытаюсь сохранить свои данные в созданной мной таблице dix ie. js. Я использую электрон и связал данные с ip c событием. Я могу видеть переданные данные в терминале macOS, я полагаю, что данные доступны и для основного процесса. Я передал данные напрямую в dex ie, но не могу их сохранить или получить. Вот код Я получаю эту ошибку в macOS-терминале, она связана с dex ie, но я не знаю, что не так.
** ОШИБКА
Dexie {
_dbSchema:
{ websites:
TableSchema {
name: 'websites',
primKey: [IndexSpec],
indexes: [Array],
instanceTemplate: [Object],
mappedClass: null,
idxByName: [Object] } },
version: [Function],
_allTables:
{ websites:
Table {
name: 'websites',
schema: [TableSchema],
_tx: undefined,
hook: [Function] } },
_createTransaction: [Function],
_whenReady: [Function],
verno: 1,
open: [Function],
close: [Function],
delete: [Function],
backendDB: [Function],
isOpen: [Function],
hasBeenClosed: [Function],
hasFailed: [Function],
dynamicallyOpened: [Function],
name: 'clients',
on:
{ [Function: rv]
addEventType: [Function: add],
populate:
{ subscribers: [],
fire: [Function: nop],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
blocked:
{ subscribers: [Array],
fire: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
versionchange:
{ subscribers: [Array],
fire: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
ready:
{ subscribers: [],
fire: [Function: nop],
subscribe: [Function],
unsubscribe: [Function: unsubscribe] } },
transaction: [Function],
_transaction: [Function],
table: [Function],
Collection: [Function: Collection],
Table: [Function: Table],
Transaction: [Function: Transaction],
Version: [Function: Version],
WhereClause: [Function: WhereClause],
websites:
Table {
name: 'websites',
schema:
TableSchema {
name: 'websites',
primKey: [IndexSpec],
indexes: [Array],
instanceTemplate: [Object],
mappedClass: null,
idxByName: [Object] },
_tx: undefined,
hook:
{ [Function: rv]
addEventType: [Function: add],
creating: [Object],
reading: [Object],
updating: [Object],
deleting: [Object] } } }
Promise {
_listeners: [],
onuncatched: [Function: nop],
_lib: false,
_PSD:
{ id: 'global',
global: true,
ref: 16,
unhandleds: [],
onunhandled: [Function: globalError],
pgp: false,
env:
{ Promise: [Function: Promise],
PromiseProp: [Object],
all: [Function: all],
race: [Function: race],
resolve: [Function: resolve],
reject: [Function: reject],
nthen: [Function: then],
gthen: [Function: then] },
finalize: [Function: finalize] },
_stackHolder:
Error
at getErrorWithStack (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:317:12)
at new Promise (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:728:29)
at Promise.then (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:757:22)
at Table.get (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:2354:16)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:54:25)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:72:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12),
_prev:
Promise {
_listeners: [ [Listener] ],
onuncatched: [Function: nop],
_lib: false,
_PSD:
{ id: 'global',
global: true,
ref: 16,
unhandleds: [],
onunhandled: [Function: globalError],
pgp: false,
env: [Object],
finalize: [Function: finalize] },
_stackHolder:
Error
at getErrorWithStack (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:317:12)
at new Promise (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:728:29)
at Promise.then (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:757:22)
at tempTransaction (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:1829:35)
at Table.getTransaction (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:2330:17)
at Table.getIDBObjectStore (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:2339:25)
at Table.get (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:2348:25)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:54:25)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:72:3)
at Module._compile (internal/modules/cjs/loader.js:711:30),
_prev:
Promise {
_listeners: [Array],
onuncatched: [Function: nop],
_lib: false,
_PSD: [Object],
_stackHolder:
Error
at getErrorWithStack (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:317:12)
at new Promise (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:728:29)
at new Dexie (/Users/z/Sites/clients-manager/node_modules/dexie/dist/dexie.js:1522:42)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:8:12)
at Object.<anonymous> (/Users/z/Sites/clients-manager/main.js:72:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3),
_prev: null,
_numPrev: 0,
_state: null,
_value: null },
_numPrev: 1,
_state: null,
_value: null },
_numPrev: 2,
_state: null,
_value: null }
** CODE
// main.js
const electron = require('electron');
const { app, BrowserWindow, ipcMain } = electron;
const Dexie = require('dexie');
// Force debug mode to get async stacks from exceptions.
Dexie.debug = true; // In production, set to false to increase performance a little.
const db = new Dexie('clients');
db.version(1).stores({
websites: "++id,client_name,hosting_provider,website_domain,panel_user,panel_pwd,db_host,db_name,db_user,db_pwd,wp_user,wp_pwd"
});
let mainWindow;
// .once('ready-to-show', () => {
// child.show();
//});
function createMainWindow(){
mainWindow = new BrowserWindow({
width: 480,
height: 150,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.loadFile( 'index.html' );
mainWindow.show();
}
app.once('ready', createMainWindow);
ipcMain.on('open-add-form', ( event, arg ) => {
//win.webContents.send('data', arg);
let addWindow = new BrowserWindow({
parent: mainWindow,
width: 1200,
height: 600,
show: false
});
addWindow.loadFile( 'add.html' );
addWindow.show();
addWindow.on( 'close', () => {
addWindow = null
});
});
console.log(db);
ipcMain.on( 'submitForm', ( event, data ) => {
// Access form data here
db.websites.add(data)
console.log(data);
});
console.log(db.websites.get('client_name'));
ipcMain.on( 'open-clients-view', () => {
let clientsWindow = new BrowserWindow({
parent: mainWindow,
width: 1200,
height: 600,
show: false
});
clientsWindow.loadFile( 'view.html' );
clientsWindow.show();
clientsWindow.on( 'close', () => {
clientsWindow = null
});
});
// add.html inline code (will be better to have this in a separate file?)
const ipcRenderer = require('electron').ipcRenderer;
//const saveBtn = document.getElementById('save-btn');
var form = document.forms;
let formData = {}
form[0].addEventListener('submit', (e) => {
e.preventDefault();
let fields = document.getElementsByTagName('input');
for( var i = 0; i < fields.length; i++ ){
// I have also a strange issue on this line
// The key:value of the object will not be the same of the order of the inputs, see dexie table
formData[fields[i].name] = fields[i].value
}
ipcRenderer.send('submitForm', formData);
console.log(formData);
});
Как вы можете видеть из некоторых комментариев к коду, у меня также есть небольшая проблема с порядком полей передаваемых данных key:value
. Я получу этот заказ, и он не будет корректным, потому что он не будет учитывать структуру таблицы
{ client_name: 'ahaii',
db_host: '',
db_name: '',
db_pwd: '',
db_user: '',
hosting_provider: '',
panel_pwd: '',
panel_user: '',
website_domain: '',
wp_pass: '',
wp_user: '' }
Любая помощь приветствуется, спасибо.
ОБНОВЛЕНИЕ Это код, который я использую в main.js
файл для вызова dex ie add метод, может быть, проблема в этом?
ipcMain.on( 'submitForm', ( event, data ) => {
// Access form data here
//console.log(data.client_name);
db.websites.put({
client_name: data.client_name,
hosting_provider: data.hosting_provider,
website_domain: data.website_domain,
panel_user: data.panel_user,
panel_pwd: data.panel_pwd,
db_host: data.db_host,
db_name: data.db_name,
db_user: data.db_user,
db_pwd: data.db_pwd,
wp_user: data.wp_user,
wp_pwd: data.wp_pass,
}).then( (primaryKey) => {
db.websites.get(primaryKey);
console.log(primaryKey);
}).then( (websites) => {
console.log(websites.client_name);
});
console.log(data);
});
console.log(data);
});
Я прокомментировал это сейчас, потому что я работаю над другими частями приложения. без этого кода я не могу проверить, хранятся ли данные ...