2017-05-28

MySQL - GROUP_CONCAT function to list one-to-many relationships as comma-separated values

SELECT
m.SectionId
, GROUP_CONCAT( d.TranslationId ) AS TranslationIds
FROM
  TABLE_1_HERE AS m
  INNER JOIN TABLE_2_HERE AS d
  ON m.SectionId = d.SectionId
GROUP BY
  m.SectionId
;

PS. In this example, a section can have multiple translations. The result will be that, for each section row, multiple translation values will be calculated inside a single field.

2017-05-26

MySQL - How to copy/rename a database/schema

$ cd /PATH_TO_MYSQL/bin
$ mysqldump -u USER_NAME_HERE -p OLD_DB_NAME_HERE >~/DUMP_FILE_NAME_HERE.sql
$ mysql -u USER_NAME_HERE -p
mysql> create database NEW_DB_NAME_HERE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> use NEW_DB_NAME_HERE
mysql> source ~/DUMP_FILE_NAME_HERE.sql
mysql> drop database OLD_DB_NAME_HERE;

2017-05-12

MongoDB & MacOS - How to create a file that will start the server on double click

Create a simple text file with the command (below is the command I use), and name it with a ".command" extension.

Then gain execution rights on it.
chmod u+x /PATH/FILE_NAME.command

The command... customize the path to fit your system.
/Applications/mongodb/bin/mongod --dbpath /PATH_TO_DATABASE

2017-05-07

RegEx - Find three-digit numbers

([0-9][0-9][0-9])+

This will also find the first three digits of, for example, number 9999.
PS. I am not convinced the last plus sign is absolutely required.

Regex - Remove brackets surrounding integer numbers

Search for "any text here: <([0-9]+)+>"
and replace it with "any other text here: $1"

This will replace "any text here: <342>" with "any other text here: 342"

Regex - Find numbers not next to character "<"

^\<([0-9])+

Of course, substitute "<" with any other desired character.