GenieFramework / SearchLight.jl

ORM layer for Genie.jl, the highly productive Julia web framework
https://genieframework.com
MIT License
139 stars 16 forks source link

Using SerachLight with Japanese values ( libraries: MySQL ) #14

Closed kaoriSG closed 5 years ago

kaoriSG commented 5 years ago

At first, I'm so sorry about my poor English but I can read and understand so please don't hesitate about using native English.

It is my very first julia + Genie app and I try to connect MySQL database and get some rows. It seems work but the values written in Japanese are broken like ...

Projects.Project
|                KEY |                                    VALUE |
|--------------------|------------------------------------------|
| client_id :: Int64 |                                        1 |
|  content :: String |                                          |
|      done :: Int64 |                                        1 |
|  estimate :: Int64 |                                   890000 |
|         id :: DbId | Nullable{Union{Int32, Int64, String}}(1) |
|     name :: String |                                 ???????? | <- this is the Japanese item
]

How I get values written in Japanese as it is ? Follows are my codes

Projects.jl

module Projects
    using SearchLight, Nullables, SearchLight.Validation, ProjectsValidator, MySQL
    export Project

    mutable struct Project <: AbstractModel

      _table_name::String
      _id::String
      _serializable::Vector{Symbol}

      id::DbId
      name::String
      estimate::Any
      client_id::Any
      content::String
      done::Int

      Project(;
        id = DbId(),
        name = "",
        estimate = 0,
        client_id = 0,
        content = "",
        done = 0
      ) = new("projects", "id", Symbol[],  
              id, name, estimate, client_id, content, done
      )

    end
end

ProjectsControllers.jl

module ProjectsController
    using Genie.Renderer, SearchLight, Projects

    function index(id::Int)
        projects = SearchLight.all(Projects.Project)
        html!(:projects, :projects, projects=projects)

    end

end
essenciary commented 5 years ago

Hi @kaoriSG - can you please share a mysql database dump with the Japanese content, so I can try it out? Thanks!

kaoriSG commented 5 years ago

Hi, @essenciary thank you for your reply and I'm sorry for late.

Follow is table dump.

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

# テーブルのダンプ projects
# ------------------------------------------------------------

DROP TABLE IF EXISTS `projects`;

CREATE TABLE `projects` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text,
  `estimate` int(11) DEFAULT NULL,
  `client_id` int(11) DEFAULT NULL,
  `content` text,
  `done` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `projects` WRITE;
/*!40000 ALTER TABLE `projects` DISABLE KEYS */;

INSERT INTO `projects` (`id`, `name`, `estimate`, `client_id`, `content`, `done`)
VALUES
    (1,'テストプロジェクト',890000,1,NULL,1);

/*!40000 ALTER TABLE `projects` ENABLE KEYS */;
UNLOCK TABLES;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Database's encoding is aliso utf8. Thank you.

essenciary commented 5 years ago

@kaoriSG Sorry for the late reply. Thanks for the dump - I'll run some tests.

essenciary commented 5 years ago

It might be an issue with your terminal... I run a quick test on SQLite and works fine (it might be MySQL specific, I'll set up a MySQL test).

|              KEY |                                    VALUE |
|------------------|------------------------------------------|
| author :: String |                                  Thi Bui |
|  cover :: String |                                          |
|       id :: DbId | Nullable{Union{Int32, Int64, String}}(1) |
|  title :: String |  The Best We Could Do テストプロジェクト |
essenciary commented 5 years ago

Looks good with MySQL too

image