New answers tagged

1

Assumed your generic MongoDB "User" object has exactly the same properties as your custom User object, you can use Object.assign for the implementation of a User constructor in one line of code, without the "30 setter calls": class User { constructor(mongoDbUser){ mongoDbUser && Object.assign(this, mongoDbUser); } //...


1

OOP and databases use data quite differently. You are modeling your OO data structure on the database's row model. The problem is that a row model has no purpose in your application, a User model does. So, create a LoginUser, that is accessed from the table, but only contains the elements needed for logging in. class LoginUser { private String name; ...


0

How to solve it? A very popular is a variant from 3: in the repository pattern a repository object acts like a container of objects, and interacts with the database for getting or changing objects. This works great, is consistent with OO style, and you could easily replace a database with another, by using a repository with the same interface but a ...


0

From your comment reply: "Are you asking how to test that the order changes between DBMSes?" yes If that is the kind of test you want to write, then this inherently has to be an integration test, where you take the same data set, store it in different data stores, fetch it back in a sorted fashion, and compare the difference in order. Something ...


0

The problem with using the object or structure returned by the database is, as you point out, That the rest of your code doesn't know what properties it has. If later you call user.name and the user doesn't have a name, you will get a run time error. Populating a Class or struct allows you to guarantee that this error wont happen. Obviously if you then go ...


-2

It just a simple concept of "Separation of Concern". The DB object holds the data for an instance of the User class object. The distinction is in the usage. For example, your application has 2 features calculate/Determine the age from the age of the user from its date of birth. borrow/lend money to another user. Note: The user has "...


0

To understand the answers to your questions, I think it'd be helpful to first talk a bit more about what an index is. The classic analogy is to compare a database index to an index in a book. Y'know, like this: Imagine that you have a cook book, and for whatever reason, recipes in the book are ordered randomly. Suppose you want to look for an Italian desert ...


0

I'd suggest a slight variation on what others have suggested: Validate the score and the sort order separately Validate the scores with some epsilon (e.g. score must be correct to 0.00001) Validate that the results order respects score order: ensure each item in the list has a score greater than or equal to (using an epsilon of 0.00001) the next item in the ...


-1

If you can change the tables' structure and you are sure that all aplications that read and write from it can use the same precision, you could store the integer part of a value in a LONG INT field and the decimals in another. For example if you have a field called amount, you could change it to amount_int and amount_dec, so 19.433325 becomes amount_int=13; ...


2

One approach would be to have two separate tests, one for the score for each result being within an epsilon range around the expected value, the other for correct ordering given the actual scores. It might still be valuable to analyze the cause of differences, and to choose a database representation which allows you to store and process values exactly the ...


14

I see the following alternatives: Tailor your test data to avoid the problem (so no two score values differ by a value as small as 10^-6) Write a special comparison function for the tests which tolerates the differences (for this, it will be better to fetch the values from the DB using the highest available precision, not by a cutted precision like 10^-5) ...


3

Redis clustering splits the cluster on two axis sharding, and replicas. Each shard is made up of one primary, and n secondary replicas. Multiple shards provide better aggregate write performance by splitting the keyspace so each shard is responsible for part of the keyspace. However more shards can decrease overall availability as if a shard is unavailable ...


1

Since you mention this in the context of deployments, I understand that those tables contain configuration or master data that make sense only to newer version able to deal with it. One way to solve this challenge, is to foresee in those tables a from_version version id that correspond to the software version from which this data starts to make sense. you ...


1

We used kafka as our storage layer for many years. It's simple and reliable and is very similar to the replicated commit log component of many databases. We just read the log into memory on startup and did all our queries directly from memory. If your queries fit the model, you can take advantage of kafka streams. This works really well for dashboard-style ...


3

I'd have to see the exact claims that Kafka can replace an RDBMS but from experience, I would say don't try to use a messaging system as a database and don't try use a database as a messaging system. These tools serve different purposes. It's like trying to bang in nails with a screwdriver. You might be able to do it but it's going to be a lot more ...


0

I know this is a little more than half a year old, but thought I might share an answer just in case. I don't have a specific answer for this problem, but I can share my use case and personal solution for inspiration. My use case for needing subgraphs: I have a chain of processes that produce output files as inputs to other processes, e.g. (Process_1)-[:...


1

The best practice of modifying database is through migrations. Although migrations usually imply schema changes, there is nothing wrong with data-only migrations. For data migrations specifically, it may be a good idea to implement these as/via higher layer components (above the business layer), to ensure that all relevant validation and other logic could ...


1

If the CRM system does not provide a mechanism for safe concurrent updates, you can't do concurrent updates safely. Period. That said, your options are basically to decide on a single source of truth, or synchronize bidirectionally with very short windows of differing data in the two systems. The single source of truth in your case would be the shop system. ...


2

There is a very good chance that evaluating the condition stops when the outcome is known. You have an expensive and precise filter, and a cheap and coarse filter. If you use the condition “coarse filter AND precise filter”, then you get the precise result, but the expensive filter will not be evaluated for everything, but just for the rows that pass the ...


1

It is absolutely fine to use the database as a coarse filter. Remember there it is hard to do unit tests of database code so we don't want the query to be too complex. If you are using most of the data you get back I think it's absolutely fine to ask for more data than you need. If you however ask for 5x-10x the data you actually need I would consider it a ...


3

They are trying to get at your knowledge of distributed systems. One of the tenets of distributed systems is unreliable clocks. You cannot count on clocks being in sync on different nodes, and you cannot reliably measure how out of sync they are. There are algorithms to gain consensus on an order of events. One common way to agree on an order in practice is ...


2

You're absolutely right not to take it for granted that a "best practice" is always in fact the best strategy. The important thing is to understand the reasons it's usually a good idea, and then make an informed decision whether those reasons apply to your case. Reasons it's usually a good idea to put as much filtering as possible on the database ...


2

First of all, do not start optimizing your database schema or imaging you can cut corners. Try to come up with more or less normalized form, which corresponds best with your business domain. Mismodelling will backfire later, it's best to try to make the model right from the start. Even such a small detail like email as the "natural primary key" can ...


2

That sounds like your policy is there to prevent data leakage, and your proposal is a way of making a run around the security policy? If a job requires data from the on-prem database, and you're not allowed to leak data from on-prem into the cloud, then you cannot run that job in the cloud.


2

I wouldn't say its a crazy approach, I mean some great software has been written from crazy approaches but there are reasons as to why this isn't a great solution. Why this isn't a good practice As VLAZ said in the comments, scalability is difficult with this approach since once you have more data, you're likely going to be performing more complex queries, ...


1

Many-to-many field. I would like to just use plain Foreign keys for my contract recipients, but I am unsure how should I assign multiple users to the same contract? Perhaps I should create a new model ContractRecipient with the user and contract as foreign keys, but that is a many-to-many field also? This many to many relationship is something that actually ...


0

A more efficient way..((O(N)[receiver notifications]) on first pull for a one to many notifications system. storing and updating in your users table is good if it is a one to one relationship. For example, if you just want to see how many messages were sent to you by ALL users rather than ONE user, this approach would be perfect. HOWEVER, for a one to many ...


2

First of all, avoiding NULL values for foreign keys seems like an arbitrary goal. If you follow it through to the extreme, it may lead you to complicated solution without bringing much value. The other point is that it's often best to keep any role-specific data out of the User data. Users of your system may have account names and passwords, possibly real-...


Top 50 recent answers are included