Sequelize example Updated 2025-07-16
To run examples on a specific database:All examples can be tested on all databases with:
./index.jsor./index.js l: SQLite./index.js p: PostgreSQL. You must manually create a database calledtmpand ensure that peer authentication works for it
cd sequelize
./testOverview of the examples:
- nodejs/sequelize/index.js: a bunch of basic examples
- nodejs/sequelize/update.js: This file is also where we are storing our expression-foo for now, e.g. how to do stuff like
col1 + col2. Such knowledge can however be used basically anywhere else however, e.g. inASorWHEREclauses, not just inUPDATE. - nodejs/sequelize/count.js: a simplified single-table count example. In practice, this will be usually done together with JOIN queries across multiple tables. Answers: stackoverflow.com/questions/22627258/how-does-group-by-works-in-sequelize/69896449#69896449
- nodejs/sequelize/date.js: automatic date typecasts
- nodejs/sequelize/like.js: LIKE
- nodejs/sequelize/camel_case.js: trying to get everything in the database camel cased, columns starting with lowercase, and tables starting with uppercase. The defaults documented on getting started documentation do uppercase foreign keys, and lowercase non-foreign keys. It's a mess.
- nodejs/sequelize/ignore_duplicates.js: ignore query on unique violation with
ignoreDuplicates: truewhich does SQLiteINSERT OR IGNORE INTOor PostgreSQLON CONFLICT DO NOTHING. Closely related Upsert versions:- Upsert
- nodejs/sequelize/upsert.js:
.upsertselects the conflict column automatically by unique columns. Both SQLite and PostgreSQL doINSERT INTO ON CONFLICT. PostgreSQL usesRETURNING, which was added too recently to SQLite: www.sqlite.org/lang_returning.html - nodejs/sequelize/update_on_duplicate.js:
.bulkCreate({}, { updateOnDuplicate: ['col1', col2'] }. Produces queries analogous to.upsert. This method is cool because it can upsert multiple columns at once. But it is annoying that you have to specify all fields to be updated one by one manually. - stackoverflow.com/questions/29063232/how-to-get-the-id-of-an-inserted-or-updated-record-in-sequelize-upsert/72092277#72092277
- stackoverflow.com/questions/55531860/sequelize-bulkcreate-updateonduplicate-for-postgresql
- Upsert
- nodejs/sequelize/inc.js: demonstrate the
incrementmethod. In SQLite, it produces a statement of type:UPDATE `IntegerNames` SET `value`=`value`+ 1,`updatedAt`='2021-11-03 10:23:45.409 +00:00' WHERE `id` = 3 - nodejs/sequelize/sync_alter.js: illustrates
Model.sync({alter: true})to modify a table definition, answers: stackoverflow.com/questions/54898994/bulkupdate-in-sequelize-orm/69044138#69044138 - nodejs/sequelize/truncate_key.js
- nodejs/sequelize/validation.js: is handled by a third-party library: github.com/validatorjs/validator.js. They then add a few extra validators on top of that.The
args: truething is explained at: stackoverflow.com/questions/58522387/unhandled-rejection-sequelizevalidationerror-validation-error-cannot-create-pr/70263032#70263032 - nodejs/sequelize/composite_index.js: stackoverflow.com/questions/34664853/sequelize-composite-unique-constraint
- nodejs/sequelize/indent_log.js: stackoverflow.com/questions/34664853/sequelize-composite-unique-constraint
- association examples:
- nodejs/sequelize/one_to_many.js: basic one-to-many examples.
- nodejs/sequelize/many_to_many.js: basic many-to-many examples, each user can like multiple posts. Answers: stackoverflow.com/questions/22958683/how-to-implement-many-to-many-association-in-sequelize/67973948#67973948
- ORDER BY include:
- nodejs/sequelize/many_to_many_custom_table.js: many-to-many example, but where we craft our own table which can hold extra data. In our case, users can like posts, but likes have a integer weight associated with them. Related threads:
- nodejs/sequelize/many_to_many_same_model.js: association between a model and itself: users can follow other users. Related:
- nodejs/sequelize/many_to_many_same_model_super.js
- nodejs/sequelize/many_to_many_super.js: "Super many to many": sequelize.org/master/manual/advanced-many-to-many.html This should not exist and shows how bad this library is for associations, you need all that boilerplate in order to expose certain relationships that aren't otherwise exposed by a direct
hasManywith implicit join table.
- nested includes to produce queries with multiple JOIN:
- nodejs/sequelize/nested_include.js: find all posts by users that a given user follows. Answers: stackoverflow.com/questions/42632943/sequelize-multiple-where-clause/68018083#68018083
- nodejs/sequelize/nested_include_super.js: like nodejs/sequelize/nested_include.js but with a super many to many. We should move this to nodejs/sequelize/many_to_many_super.js.
- two relationships between two specific tables: we need to use
as:to disambiguate them- nodejs/sequelize/many_to_many_double.js: users can both follow and like posts
- nodejs/sequelize/one_to_many_double.js: posts have the author and a mandatory reviewer
- hooks
- internals:
- nodejs/sequelize/common.js: common utilities used across examples, most notably:
- to easily setup different DBRM
- nodejs/sequelize/min_nocommon.js: to copy paste to Stack Overflow
- nodejs/sequelize/min.js: template for new exapmles in the folder
- nodejs/sequelize/common.js: common utilities used across examples, most notably:
Universal asynchronous receiver-transmitter Updated 2025-07-16
A good project to see UARTs at work in all their beauty is to connect two Raspberry Pis via UART, and then:
- type in one and see characters appear in the other: scribles.net/setting-up-uart-serial-communication-between-raspberry-pis/
- send data via a script: raspberrypi.stackexchange.com/questions/29027/how-should-i-properly-communicate-2-raspberry-pi-via-uart
Part of the beauty of this is that you can just connect both boards directly manually with a few wire-to-wire connections with simple jump wire. Its simplicity is just quite refreshing. Sure, you could do something like that for any physical layer link presumably...
Remember that you can only have one GNU screen connected at a time or else they will mess each other up: unix.stackexchange.com/questions/93892/why-is-screen-is-terminating-without-root/367549#367549
On Ubuntu 22.04 you can screen without sudo by adding yourself to the
dialout group with:sudo usermod -a -G dialout $USER Universal Module Definition Updated 2025-07-16
Since JavaScript devs are incapable of defining an unified import standard, this design pattern emerged where you just check every magic global one by one. Here's a demo where a Js library works on both the browser and from Node.js:
Universal quantum gates Updated 2025-07-16
Just like as for classic gates, we would like to be able to select quantum computer physical implementations that can represent one or a few gates that can be used to create any quantum circuit.
Unfortunately, in the case of quantum circuits this is obviously impossible, since the space of N x N unitary matrices is infinite and continuous.
Therefore, when we say that certain gates form a "set of universal quantum gates", we actually mean that "any unitary matrix can be approximated to arbitrary precision with enough of these gates".
Or if you like fancy Mathy words, you can say that the subgroup of the unitary group generated by our basic gate set is a dense subset of the unitary group.
Schwinger effect Updated 2025-07-16
Soviet Union Updated 2025-07-16
SQLite benchmark Updated 2025-07-16
SQL prefix column names with the table they came from Updated 2025-07-16
Ultraviolet catastrophe Updated 2025-07-16
What is the Ultraviolet Catastrophe? by Physics Explained (2020)
Source. Universities are obsessed by their images Updated 2025-07-16
Concatenate two videos with ffmpeg Updated 2025-07-16
Organization developing quantum control systems Updated 2025-07-16
University Updated 2025-09-09
As of 2020, university has the following very important applications:Notably, Education is an IQ test, not a way to learn useful and beautiful things.
- meet an intelligent sexual partner (see also: Section "Sexual selection", Section "The main function of university is sexual selection") and or have fun and or come out of the closet
- get you in debt if you are from the United States
One major issue is that teachers don't have the right incentive to, nor are selected to, teach well. Thus the existence of Rate My Professors! But we can do better...
Which is why Ciro Santilli wants to destroy its current format with OurBigBook.com. He believes that we can find a more efficient organization to achieve both the social and research functions of university, by first doing as much as possible online
City in the Netherlands Updated 2025-07-16
Science and Technology Facilities Council Updated 2025-07-16
SubStation Alpha Updated 2025-07-16
University entry exam Updated 2025-07-16
They mean that until you are 18, you have to study a bunch of generic crap you hate just to get into university. Rather than studying whatever it is that you truly love to become a God at it as fast as possible and have any chance of advancing the field.
And then, if you decide that you want to change, which is not unlikely since you haven't really try to study what you signed up for before then, it can be very hard and time consuming, leading to a bunch of adults with useless degress they will never use at work.
University entry quotas Updated 2025-07-16
Ciro Santilli is against affirmative action university entry quotas that reserve spaces e.g. for students from discriminated races or poor families. Instead, he believes that affirmative action should take place on earlier stages of education as described at: free gifted education.
Notably, Brazil has implemented a very heavy university entry quota system after Ciro had left university there: www.bbc.co.uk/news/business-23862676
This is of course easy for a white male from a privileged background to say, and infinite debate has already been had on this matter, but here goes again.
First, in defense to the personal attack, Ciro raises the fact that he has dedicated large chunks (all?) of his life to open source software and knowledge in general, which Ciro believes is the only way to actually make the world fairer to poor countries. His money (time) is where his mouth is.
One good argument in favor of the Brazilian quota system, is that the kids who enter university because of quotas do just as well as those who don't.
Ciro has actually believes that this is possible, and offers the following possible explanation: most of pre-university knowledge is useless, and university selection system is crap, and Ciro wants to destroy it with a system in which anyone can learn university stuff from home.
Both the top end of the quota and non-quota kids are basically equally capable of doing useful stuff therefore.
And possibly more importantly than knowledge, Ciro saw many of his colleagues (basically all of which were from relatively privileged backgrounds) "do badly" in university, because of lack of motivation, because they had chosen a course only to find that they were not interested in it because the existing high school educational system is crap and does not help them find what they love and because it costs you several years of your life to change your choice in most universities (long live École Polytechnique).
Maybe the fact that poor kids know that they are fucked if they fail, and so they have to succeed at any cost, might also help with motivation. Which is a terrible terrible thing, because only those who have to leeway to take risks end up taking them and making the the next big thing.
Ciro believes instead that only once kids have learnt university level stuff in their area of interest for free on the Internet should they go through selection based on that specific and much more concentrated useful knowledge.
And this competition must only be used to distribute resources which you can't learn from fucking computers:
- laboratories. Actually, one of Ciro's most important advices to kids nowadays is: when in doubt, choose the course that has the most experimental work
- one to one mentorship on advanced master thesis/PhD level projects
Once this point knowledge is reached however, it starts to become unclear if a single "everyone takes the same test to avoid discrimination" test is feasible anymore, and we start entering the much more relevant (and potentially discriminatory) "I am a teacher trying to advance the state of the art, and I need a person mildly skilled in the art to do some slave labor for me", which is PhDs selection work.
If quota are in place, what will happen is that parents of the rich kids will start investing less in education, and possibly just put their kids in high schools, and do home schooling instead. This would therefore reduce the total investments the country makes in education!
Outside of the obvious technical evolution proposed, Ciro is a huge proponent of free gifted education. Or closely related, creating scholarships that focus on poor students. The entry requirements should be the same, but once you qualify, everyone should have enough money to lead a decent life during their studies.
Then let those kids pass exactly the same university entry exams, and watch them crush the average privileged kids.
This advice is similar to what is mentioned at: what poor countries have to do to get richer. When you don't have money to do everything, you must select a few good bets and focus on them. You can't pay a lot to every public school teacher, so you must select a few select places that need it the most. As those smart bets pay off, you start to have more and more money to expand the system further.
Inside Westside Barbell by Vice News (2018)
Source. One sentence of this nice documentary about the notorious Westside Barbell gym where the openly pro-performance-enhancing-drug powerlifting legend leader and cult-leader-like personality Louis Simmons teaches just stuck to Ciro Santilli's mind. His top tenant and manager Tom Barry talks about Louis:Ciro admires this level of focus, directness and meritocracy. Just don't take drugs, children. Louis' creation of a cult-like training atmosphere is another interesting aspect, see also: Section "Group students by interest, not by age".
The man [Louis] lives in his own world, and he just rejects everything outside of it, it doesn't matter. Like: "what's your name"? He doesn't care. If you lift numbers, he cares about that, that's more important.
University has become a luxury item Updated 2025-07-16
medium.com/left-right/the-education-system-is-about-to-implode-5c95f774b523 The Education System is About to Implode by Nicholas Budny (2020)
Stanford, MIT, Harvard and Oxford are luxury goods in the same sense that a Mercedes-Benz might be, or the latest iPhone. They sell an aesthetic experience that provides the consumer with social status, similar to acquiring expensive clothes or a fancy house.
Bar scene from Good Will Hunting
. Source. This scene is way way overdone. But: Collecting Updated 2025-07-16
Unlisted articles are being shown, click here to show only listed articles.