#NO SQL
Explore tagged Tumblr posts
Text
Databases
What are databases?
First, what are databases for?
Storing data in your application (in memory) has the obvious shortcoming that, whatever the technology you’re using, your data dies when your server stops. Some programming languages and/or frameworks take it even further by being stateless, which, in the case of an HTTP server, means your data dies at the end of an HTTP request. Whether the technology you’re using is stateless or stateful, you will need to persist your data somewhere. That’s what databases are for.
Then, why not store your data in flat files, as you did in the “Relational databases, done wrong” project? A solid database is expected to be acid, which means it guarantees:
Atomicity: transactions are atomic, which means if a transaction fails, the result will be like it never happened.
Consistency: you can define rules for your data, and expect that the data abides by the rules, or else the transaction fails.
Isolation: run two operations at the same time, and you can expect that the result is as though they were ran one after the other. That’s not the case with the JSON file storage you built: if 2 insert operations are done at the same time, the later one will fetch an outdated collection of users because the earlier one is not finished yet, and therefore overwrite the file without the change that the earlier operation made, totally ignoring that it ever happened.
Durability: unplug your server at any time, boot it back up, and it didn’t lose any data.
Also, a solid database will provide strong performance (because I/O is your bottleneck and databases are I/O, so their performance makes a whole lot more of a difference than the performance of your application’s code) and scalability (inserting one user in a collection of 5 users should take about the same time as inserting one user in a collection of 5 billion users).
ACID is a cool acronym! CRUD is another cool one
You will definitely run into the concept of “CRUD” operations. It’s just a fancy way to refer to the 4 operations that can be performed on the data itself:
Create some data;
Read some data;
Update some data;
Destroy some data.
Obviously, a database should allow all four. Yes, that’s it.
2+ kinds of databases
When people talk about databases, they’re usually referring to relational databases (such as PostgreSQL, MySQL, Oracle, …); but there are many other kinds of databases used in the industry, which are globally referred to as “NoSQL” databases, even though they can be very different from each other, and serve very various purposes. Also, the name “NoSQL” comes from SQL, which is the name of the syntax used to give orders (CRUD operations, creating and deleting tables, …) to a relational databases; however, some non-relational databases, which are referred to as “NoSQL” give the option to use the SQL syntax. Therefore, the term “NoSQL” is quite controversial to refer to non-relational databases, but it is still widely used.
“NoSQL” (non-relational) databases have known a boost in popularity, over the last decade or so, so much that there was a point, a few years ago, where people were wondering if they were to replace relational databases entirely. But years later, the market has now solidified, NoSQL databases’ market share doesn’t progress much anymore and is now quite steady. The result: many NoSQL databases have made it into solid maturity, and are used in some very ambitious projects (as well as small ones), but relational databases are still by far the most used in projects, and are not going anywhere after all.
Therefore: it is crucial for a software engineer to know very well how relational databases work, because the odds are very strong that you will encounter them in your career; but it is also very important to get acquainted with the most popular types of NoSQL databases, because the odds that you run into them, however kinda smaller, are pretty strong too.
SQL
In order to work with relational databases, you will need to get familiar with SQL syntax. A lot of developers will acknowledge that they find the SQL syntax unpleasantly hard to use, which has some outcomes:
Engineers that are comfortable with SQL are very respected in the industry, even more so in this age where data has gotten so valuable. To be honest, the fact that I aced the SQL challenge on my Apple interview is probably a huge reason for me to have gotten the job; it turns out the initial role was a lot about manipulating data.
The fear of SQL explains a lot why non-relational databases got called “NoSQL”, a bit like if it was a statement, a complain. Non-relational databases push a lot the button of not having to use SQL.
Modern full-fledged frameworks contain tools that are called ORMs, and one of their roles is to abstract away SQL queries (which is good for day-to-day ease of use, but can turn out very dangerous). We’ll cover ORMs more later, but it’s worth noting that you do find back-end engineers in the industry who work with relational databases, but never write a line of SQL, which makes them a lot less valuable on a project.
For a beginner, keep in mind that SQL’s syntax is a bit hard to wrap your head around, so maybe you should follow a tutorial first. Please don’t try to memorize the SQL syntax. I’ve used SQL extensively in very advanced cases, on systems with hundreds of millions of records, and I still go on Google each time I need to compose a SQL query.
Some terminology around relational databases
One good thing about relational databases is that whether they’re PostgreSQL, MySQL, Oracle, or other, they’ve managed to be pretty consistent across brands. Therefore, not only are their versions of SQL pretty decently similar (at least for CRUD operations), but the terminology they’re using are mostly the same.
Say you need to store users. To do that, you create a table that is called “users”.
Your users have 3 pieces of information to store: their “id”, their “login”, and their “password”. Those are called columns, and they all have types, like integer for the “id”, varchar(32) for “login” (a string of variable length, but maximum 32), and char(32) (a string of exactly 32 characters, which is the case for all text encrypted with the md5 algorithm, for instance). The available types may vary heavily from one database “brand” to the other.
Now, let’s add a user in the database with SQL:
INSERT INTO users (login, password) VALUES ('rudy', '01234567890123456789012345678901');
This adds a row in the table (sometimes also refered to as a record, or more rarely, a tuple).
Why are they called “relational” databases?
Historically, the initial reason was that tables used to be called “relations” (they gather a lot of datas that are “related” to each other, since they follow the same structure). However, tables are now tables, and the term “relation” has now been recycled for another use.
A relation as used today is something that ties two records together, most often across different tables. For instance, say you have a blog, and you have 2 tables:
posts, with the fields id, title and body
comments, with the fields id and body
In both tables, the “id” fields are primary keys, because they uniquely identify the row that they belong to (if you say “give me the post of id 4”, you’re sure to be getting only one post).
But how do you know that a given comment is attached to a given post. Well, you add a postid field to the comments table, containing the id of the post you with to attach it to. The postid field is called a foreign key, uniquely identifying another’s table primary key.
Now that you have that, you can easily identify, from a comment, which post it is attached to; but you can also easily identify, from a post, which comments are attached to it. Just fetch the comments whose post_id field contain the id of the post you had in mind. The fact that you can do that is what is called a relation.
Once you have your relation, you can do pretty advanced things. For instance, you can join tables together while querying them, which will allow you to search for “the comments whose posts were published within the last month”, for instance (well, provided the posts table has a published_at column of type date, for instance).
Note: you can have a relation between rows of the same table, for instance, a user that is the “sponsor” of another one, a comment that is a “reply” of another one, …
Some more terminology around relational databases
Indexes
Say you want to get all of the comments that are attached to the post of ID 12:
SELECT * FROM comments WHERE post_id=12;
If you have millions or billions of comments, having your database extract the comments that match this condition can be amazingly time-consuming. Therefore, you can add an index on the comments table, that applies to the post_id column. This will “precompute” every possible SELECT query with WHERE conditions on this column, which will update themselves every time you modify data, so that those calls are ready to respond very quickly.
Let’s complicate things a bit, and say you want to optimize this query:
SELECT * FROM comments WHERE post_id=12 AND published=1;
Your index on the post_id column might not help much on that query. However, for that query, you can absolutely define an index on multiple column (in this case, the columns post_id and published).
Setting indexes properly is a known quick win to improve performance of relational databases on queries that are performed very often and take a long time to respond (so-called slow queries). I can quote at least a dozen occurrences in my career where setting up an index properly boosted a database’s performance with minimal effort, the most notable of which allowed us to boost a data migration that was taking ~48 hours, to suddenly complete in about 3 hours.
Joins
You can join tables together that have relations between each other, so that you can operate on data across those tables. For instance, I want the titles of all posts that have published comments.
SELECT posts.title FROM posts JOIN comments ON posts.id = comments.post_id WHERE comments.published=1;
(Note: each post on that query will appear as many times as it has comments, but let’s focus on the join for now.)
Performance is dramatically better if you manage to get the database to do most of the work, as opposed to your application, because the database knows most about your data and how to handle it most efficiently. Joins are amazing wins for that, because the other way to get it done is to perform many separate SQL queries, and manipulate that data in your code, which is very inefficient.
Note: you can join tables together across many relations. The largest join in my career was 7-fold, in a database at Apple that contained information about localization projects.
A NoSQL kind of database: document-based databases
One particularly popular type of NoSQL database is document-oriented databases, such as MongoDB or CouchDB. One reason they’re popular is because their learning curve is very smooth, and they feel natural to use: you just send them JSON documents, much like we’ve done in the “Relational databases done wrong” project, and they make it right when you need to fetch them back. You don’t need your JSON documents to have specific fields of specific types, just send whatever JSON you want; the technical word for this is that they are schemaless.
One caveat is that they’re much, much harder to scale than relational databases (the data being more “formatted” in relational databases makes it easier and faster to work with).
Another caveat is that there is some comfort in having the database enforcing a schema (proper columns of proper types, …); if the database doesn’t do it, you can expect that some JSON documents in the collection are not of the schema you expect, and then you have to enforce schema in your code, which means more work. As a result, some document-based databases offer ways to enforce some schema, but I don’t believe many developers use it, because it defeats the purpose of having schemaless storage.
Just as relational databases, document-based databases offer a variety of extra features to tune your usage of the data: indexes, joins, … sometimes even relations!
Document-based databases will be covered towards the end of year 1.
Another NoSQL kind of database: key-value stores
Some applications may need very large key-value storage, which you may think of as the persistence of a single huge “dictionary” structure (the same structure that Ruby calls “hash”, Python calls “dict”, PHP calls “associative array”, Objective C and Swift calls “dictionary”, …). An obvious need for that is around caching (if you don’t understand why, we’ll cover this when we talk about caching). Cassandre, memcached and Redis are popular key-value stores.
As your collection of key-values grows, you may need pretty advanced ways to organize them (and expire them, for instance), so, obviously, each key-value storage solution comes with more advanced tools than just the usual CRUD operations.
At the intersection of NoSQL and relational
As mentioned before, NoSQL databases sometimes get closer to relational databases by allowing to be queried using the SQL syntax (like Cassandra and Hypertable); but databases are getting closer also the other way around, as relational databases themselves have started offering some document-based storage.
A mature example of that is PostgreSQL’s “hstore” type, which allows to store JSON data in PostgreSQL, in a way that is queriable. Most recently, this has allowed PostgreSQL to have a certain leg up against their competition of open-source relational databases, because MySQL hasn’t been able to ship a similar feature yet, although they’re expected too (MySQL development has dramatically slowed down now that they belong to Oracle, which is a direct closed-source competitor; a few years ago, most MySQL contributors went ahead to create another open-source database called MariaDB, which never really became mainstream, so maybe there won’t ever be document-based storage in MySQL, actually).
What NoSQL storage do I need?
NoSQL databases address all kinds of requirements, and therefore the ways they work are dramatically different. Here’s a really accurate map of the various solutions: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
Note: in year 1, your main project must be done using a relational database, and we’ll cover document-oriented databases (probably MongoDB) and key-value stores (probably Redis) towards the end of the year.
0 notes
Text
Happy (early) Valentines Day! Have some virus yaoi.
Slammer (Metal) Sonic— @moderator-monnie
Support me on Ko-Fi
#art#fanart#doodle#ship art#crackship art#sonic.exe#sql slammer worm#slammer sonic#sonic horror au#contaminated! au#crackship#does this also count as metonic?
451 notes
·
View notes
Text
Face-off
Part 2 - Qiao Ling & Cheng Xiaoshi
page 1 - 2
main post
#already 9 pages on my kofi!!#promise the comfort is coming in this one#(after a lil bit of angst ofc)#SIBLINGS TIME!!#get his ass sql#(by that i mean talk to him and then give him a hug)#face-off comic#dx comic#link click#linkclick#sgdlr#时光代理人#shiguang dailiren#cheng xiaoshi#qiao ling#dx art stuff#lu guang
183 notes
·
View notes
Text

Like I said, I don't have the bandwidth to do a daily art challenge this October, but that I'd do /some/ mxtxtober. And I HAD to do prompt 4: Wine Bottle 👀
#mxtxtober#mxtx#svsss#scum villain's self saving system#scum villain#ren zha fanpai zijiu xitong#sql#lbh#lmy#shen qingqiu#luo binghe#liu mingyan#the taoist nuns#wine bottle
211 notes
·
View notes
Text
Do not help them to build any more of this machine.
If you work with a database and are asked to alter the table structure to comply in advance for citizenship or gender categorizations it's really important to NOT do it.
"The governor is concerned about all this stuff they want us to update our record keeping so we store both gender AND biological sex."
"We need fields to store the country of origin of people's parents."
If you don't have the power to rebuff this yourself, ask for help. At minimum ask for help online anonymously.
Depending on your job you probably have in the past made compromises. Maybe to keep your job. Maybe to survive. This is a bright line. If you are asked to be the one to update the table don't let it be your fingers typing those changes.
If you can't just say "No I won't do that." Stall, run away, feign incompetence. Just don't let it happen.
I suspect this might be where the rubber hits the road first for us around here.
Nothing has changed. You do not have to do it. It is not even ordained.
I know someone who rebuffed such a request. Boss was apologetic "it's what the higher ups want, oh *I* think it's a lot of nonsense, but I don't want us to be out of step ... blah blah"
It was proposed to them in sheepish way. They said it would be a lot of work, not add anything of value, and most important they would not do it. It didn't come up again.
Fascism can be the work of zealots, but there are also many sheepish middle management helping hands who "don't even believe in this really"
There is a lively discussion of this on mastodon. (Mastodon is a very active social network where many people who left twitter have gone over the past few years to escape many problems of big centralized socail media. I like it a lot.) Posting a response to this post over there could be a way to get lots of help and ideas from tech people all over the world with similar values. If you do need help. Please say something.
Also, if you respond to this post I can pass what you say along if that would help too. People will respond and give you ideas to NOT do this should you be asked.
130 notes
·
View notes
Text


Good morning. ☕ Last night, I took and passed my Database Management Applications exam, which was the last exam in my degree program. Here's a pic of some of my notes (which I intended to post the other night while I was actually studying).
I have until April 30 to complete my capstone project if I'm going to finish by the end of the term. (I do qualify for a one-month extension, though. I went ahead and requested it just in case I need a few extra days.)
Lots of research and writing will be happening over the next week. 📚
48 notes
·
View notes
Text
Enough of the gif/jif discourse
94 notes
·
View notes
Text
Robert ("Bobby") Tables DOES exist!
Summary translation: Students have been waiting for test results/grades for over a week because they use an automated test reader/parser/grader and someone *wrote an SQL injection on the paper test* and successfuly did the ol' DROP TABLES on the college's records, and they didn't keep backups of the databse
319 notes
·
View notes
Text
Challenge for artists for fun! (Create A Slammer Clone Oc!)
Create your own 'clone' copy for Slammer.
What Is A Slammer Clone/How to describe one?
1: It can take the form of any character. (Not limited to the Sonic Series.)
2: It can take the form of any insect that, (lays eggs and has a larva stage at some point.)
Rules:
1: They must have empty eye sockets on their face, however they can have an eye or eyes. Somewhere else on the body.
(You can decide the placement on the body.)
2: These Two Colors Must Be Used Somewhere In The Design.
3: Sonic, Shadow, Tails, Amy and Mario already have Slammer Clones/an insect assigned to them, so they can't be used.
4: have fun!
Slammer Sonic for reference art by lazy-charlie
#sonic the hedgehog#sonic horror au#sonic.exe#slammer sonic#sonic.exe au#sonic.exe oc#sql slammer worm#art challange#create your own 'slammer clone' oc!#fun lil challange#if your interested go ahead! I'd love to see the creepy bug infested chararters you make!#reblog this post if you plan to take up the challange!#tw: worms#tw: body horror#I will reblog every submission done for the challenge and put my thoughts in the tags!
58 notes
·
View notes
Text
Hear me out
A The Beholding ritual but it’s just some guy given some enormous spooky database and they have to come up with as many useful sql views for it
(Doing my databases homework for hours and listening to TMA at the same time does interesting things to my mind and it full on feels like some ritual)
#the magnus archives#tma podcast#tma#tma shitpost#the beholding#i am actually getting sql dreams at this point#like the whole dream is an sql file#and im writing queries#except my dream is adding difficulty because now there is apparently an sql timer dlc#and i have to time everything perfectly or it breaks
29 notes
·
View notes
Text



#tiktok#elon musk#elongated muskrat#fuck elon#fuck musk#fuck doge#doge#trump administration#trump adviser#trump and musk#us government#us politics#us presidents#elon musk is a fraud#trump is a fraud#sql#excel#donald trump#trump's america#trump's second term
39 notes
·
View notes
Text
No idea if this person follows me BUT while the industry standard for GIS software (ArcGIS pro) is incredibly expensive, there are open source alternatives like QGIS. A lot of governments and organizations also have open data portals that you can grab data from (shapefiles, CSVs, rasters, whatever).
I've kind of been taught ground-up in person so I don't have recommendations on video tutorials for teaching basic concepts sadly. Bolstadt GIS fundamentals is good and was dirt cheap by textbook standards though (was like $40 iirc).
"Learning GIS" I guess also depends on what you want to do with it? If you want to mess around with cartography and data visualization you could probably just give yourself some pet projects.
#of course i would never. never pirate a textbook. cough.#i like highlighting while reading though so im happy i bought a physical copy of that one specifically#iirc open source GIS software also requires you to lean on SQL and python a little more. though i could be wrong#not art
30 notes
·
View notes
Text
Happy (slightly late) Halloween! Have these two goobers on this spooky day.
SQL!SLAMMER— @moderator-monnie
663 notes
·
View notes
Text


Очень зацепила эта фраза в новелле
#art#bjyx#fanart#my art#poster#bjyxszd#xiao zhan#yizhan#the untamed#sql#wei wuxian#wei ying#yiling laozu#grandmaster of demonic cultivation#wangxian#photoshop
84 notes
·
View notes
Text
This faggot just got a B in their SQL class :3
41 notes
·
View notes
Text
praying to the patron saint of fake it til you make it at a job you're only halfway qualified for (moist von lipwig)
#beck posts#discworld#moist von lipwig#(pretending to know how to read sql queries while on camera) this is happened to my good friend moist
21 notes
·
View notes