Tag: database

MySQL: Convert Character Set and Collation

The character set and collation changes for a DB have important changes on the storage requirements and query result behavior. The character set for a table can be changed in two ways: a. Using CONVERT TO query b. Using MODIFY <column name> Methods The CONVERT TO method makes sure that each column fits the new…

How to: MySQL Get Database Name and Use in Another Query

How to: MySQL Get Database Name and Use in Another Query The following SQL query get the database name and use the name to run another query. SET @dbname = DATABASE(); ALTER DATABASE @dbname CHARACTER SET utf8 COLLATE utf8_unicode_ci; References https://stackoverflow.com/questions/8096550/mysql-determine-which-database-is-selected https://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8 https://stackoverflow.com/questions/49735318/mysql-how-to-find-current-database-assign-it-into-a-string-variable https://dev.mysql.com/doc/refman/5.7/en/set-variable.html

Database Collation and UTF8MB4

Database collation defines how characters are compared and hence the order of rows in query results. Popular Encodings UTF8: Uses 3 bytes for a character UTF8MB4: Uses 4 bytes for a character, so allows more characters. How to Decode Collation utf8mb4_unicode_520_ci UTF8MB4 Unicode 5.2.0 comparison for characters ci: Case Insensitive comparisons Reference https://stackoverflow.com/questions/37307146/difference-between-utf8mb4-unicode-ci-and-utf8mb4-unicode-520-ci-collations-in-m# https://www.monolune.com/mysql-utf8-charsets-and-collations-explained/ Written…

Go, gorm, nested JSON and associations

Go, gorm, nested JSON and associations gorm provides a clean way to store a nested JSON with the relation of associations among tables. The following code creates a DB with three levels of nesting. package main import ( “encoding/json” “fmt” “github.com/jinzhu/gorm” _ “github.com/lib/pq” ) const ( host = “localhost” port = 5432 user = “postgres”…

Design Pattern: Active Record

Active Record An Active Record Object represents a row in a DB table. The object has fields mapping to a column in the table and methods to access table data. Active Record connects classes to relational database tables to establish an almost zero-configuration persistence layer for applications. The library provides a base class that, when…

Mongo DB: Good to know things

Mongo DB is a No-SQL, free, open-source solution that is highly scalable, highly available and high performance solution. Engine is coded in C++ Works in a client-server model Major components: mongod: The storage server mongos: The sharding server config server(s): Stores metadata that accomplish sharding Is actually a mongod process Mongo provides write operations durability…