SQL:SQL数据库中的链接列表?(SQL : Linked lists in SQL database?)
有一个结构问题,我不知道如何准确解决。
我正在做一个库存系统 - 应该支持多个商店,每个商店都有自己的商品数据库,前100个商店有50.000个商品号。
itemnumber数据库是全局的(所有商店都是相同的itemnumbers) - 但由于我需要跟踪每个商店的库存数量,我假设我需要为每个商店创建一个本地副本,那就是很多表和很多冗余数据。
但令我头疼的是,对于每个库存(他们从整个库存计算完整的商店) - 我需要添加新的库存数量pr项目编号(和一些结果字段,更正库存与原始库存等) - 这是应该添加的东西每次他们选择完成补货/重新计票。
假设itemdatabase是:
itemno,description,现在总库存
然后对于新的库存,当它完成时我需要将这3个值添加到记录中 - 如果他们选择做ex。 200个库存计数我需要在每个项目中添加200个这样的集合:
库存积分,总计数,差异(总计数 - 总计数)
因为我必须能够为每个新的重新进货/重新计数(库存会话)执行此操作,并将每个结果保存为事件历史记录,所以我不能(我认为)在SQL中将动态字段添加到当前表结构中。
如果我有某种链表,我可以让它在我的脑海里工作 - 其中itemrecord上的链表代表了库存会话的字段集 - 所以不是将50.000条记录的完整副本复制到另一个表中对于每个库存会话,我将能够通过包含2的链表扩展表。
另一个选择是某些关系的东西,我想有几个表,但这变得复杂,我担心它需要的所有查找。
是否有可能以正确的方式在SQL数据库中以某种方式使用链表结构或此类问题? 或者你会建议我使用另一个数据库而不是SQL?
Have a structual question i dont know how to solve exactly.
Im doing an inventory system - where there should be support for multiple stores, each with their own item database, ex 100 stores with 50.000 itemnumbers.
The itemnumber database is global ( same itemnumbers for all stores ) - but since i need to keep track on stock count in each store, i assume i would need to create a local copy per shop, thats alot of tables and alot of redundant data.
But my headache is that for each inventory ( they count the complete shop from scrath ) - i need to add the new stockcount pr itemnumber ( and some result fields, corrected stock vs original stock etc. ) - and this is something that should be added each time they choose to do a complete restock/recount.
lets say the itemdatabase is :
itemno, description, total stock now
Then for a new inventory when its completed i need to add these 3 values to the record - if they chose to do ex. 200 inventory counts i would need 200 of these sets to be added per itemnumber :
inventorysession,total count, difference (total count - total count)
Since i have to be able to do this for each new restock/recount (inventory session), and keep the results for each as a history of events, i cannot ( i think ) in SQL add dynamic fields to the current table structure.
I could get it to work in my mind if i had some kind of linked list - where the linked list on the itemrecord would represent the sets of fields pr inventory-sessions - so instead of making a complete copy of the 50.000 records into another table for each inventory session, i would be able to extend the table throuh a linked list which would contain the 2.
Another option would be some kind of relational thing with several tables i guess, but that gets complicated and i worry about all the lookup's it would require.
Is it possible in a correct way to somehow use a linked list structure or this kinda of problem in a SQL database ? or would you advice me to use another database instead of SQL ?
原文:https://stackoverflow.com/questions/37098131
最满意答案
确保:
1) Postgres db is running 2) pg is installed:
npm install --save pg
3) Add also protocol to your config
'dialect':'postgres', 'protocol':'postgres'
Make sure:
1) Postgres db is running 2) pg is installed:
npm install --save pg
3) Add also protocol to your config
'dialect':'postgres', 'protocol':'postgres'
相关问答
更多-
经过多次调试,我找到了解决方案 app.get('/users', (req, res) => { User.findAll({ where: { '$Task$': null, }, include: [ { model: Task, required: false, }, ], }).then(function(todo) { res.json(todo); }); }); 通过添加此w ...
-
所以从理论上讲你的代码片段应该可行,但是sequelize代码会抛出一个我怀疑会误导的错误。 您需要编辑lib/transaction-manager.js文件,因为它会吞下您需要的错误详细信息。 在throw之前在catch块中添加一个console.error(err) ,以确保错误不是别的奇怪,就像你的sequelize安装缺少文件或没有正确处理Windows路径或类似的东西。 进行一次更改,重新运行您的代码段,并使用详细信息更新您的问题,如果这不会直接导致根本原因和解决方案。 So in theor ...
-
按列名称续订订单(Sequelize order by column name)[2021-11-21]
使用字段更新您的模型,它会没事的 var Milestones = sequelize.define('milestones', { milestoneId: { type: Sequelize.INTEGER, field: 'milestoneId' }, data: Sequelize.JSON, repository: Sequelize.STRING }); 编辑: 也用更新订单 order: ['milestoneId'] Update your model ... -
您无法使用箭头功能,因为他们无法访问this 。 尝试像这样写他们 - // Instance methods User.prototype.testFunction = function testFunction() { this.firstName = "John"; } // Class methods User.anotherTestFunction = function anotherTestFunction() { User.findOne().then(() => doSomethi ...
-
在创建表(在数据库中)后添加了关系吗? 如果您修改了您的方案并再次运行您的程序,则需要.sync({ force: true }) 。 如果数据库中尚不存在该表,Sequelize将只创建该表及其所有引用。 在所有关联完成后您是否调用同步? 你在使用InnoDB吗? 奇怪的是,我可以重现,最简单的解决方法是手动定义密钥,我认为,这就是我解决它的方法,可能是一个错误,否则我不确定。 请参阅: http : //sequelizejs.com/docs/latest/associations#block-3-l ...
-
确保: 1) Postgres db is running 2) pg is installed: npm install --save pg 3) Add also protocol to your config 'dialect':'postgres', 'protocol':'postgres' Make sure: 1) Postgres db is running 2) pg is installed: npm install --save pg 3) Add also protoco ...
-
最后想想这个问题 ,感谢Sean在这个Stackoverflow问题中给出的答案 - 我在bin中为我的数据库连接(db.js)创建了一个新文件,并导出了sequelize doing module.exports = sequelize; 然后我就可以在执行var sequelize = require('../../../bin/db'); 我仍然不确定为什么我的早期方法不起作用 - 当我在其他文件中需要它时,bin / www的导出返回了一个空对象。 我认为这与异步行为有关,因为当我启动nodemon ...
-
Sequelize'方言需要从v4.0.0开始明确提供'(Sequelize 'Dialect needs to be explicitly supplied as of v4.0.0')[2022-03-26]
你只需在初始化sequelize时提供方言; const sequelize = new Sequelize('database', 'username', 'password', { host: 'localhost', dialect: // pick one of 'mysql','sqlite','postgres','mssql', }); You simply supply the dialect when you initialize sequelize; const sequeli ... -
看起来您的NODE_ENV与development , test或production ,因为如果它与任何一个匹配,您将获得类似的消息 Loaded configuration file "config/development.json". Using environment "development". Unable to connect to database: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306 但 ...
-
ExpressJs与续集(ExpressJs with sequelize)[2021-09-23]
要使用CLI,您需要安装相应的包: npm install --save sequelize-cli 有关可用命令的更多详细信息可以通过help命令获得: $ sequelize help:init $ sequelize help:db:migrate $ sequelize help:db:migrate:undo 有关更多信息,请使用此链接Sequelize In order to use the CLI you need to install the respective package: np ...