Permalink
Browse files

feat(SchemaBuilder): add support for collate and charset

  • Loading branch information...
RWOverdijk committed Jun 22, 2017
1 parent b1f0d68 commit d18d9ffb87f44c7aab054dfad84efa86215857ac
Showing with 25 additions and 1 deletion.
  1. +12 −0 src/SchemaBuilder.ts
  2. +11 −1 src/SnapshotManager.ts
  3. +2 −0 test/resource/entity/shop/product.ts
@@ -246,6 +246,18 @@ export class SchemaBuilder {
code.push(`\n${spacing()}builder.schema.${action}Table('${tableName}', table => {`);
spacing(2);
if (action === 'create' && actionData.info.meta) {
let meta = actionData.info.meta;
if (meta.charset) {
code.push(`${spacing()}table.charset('${meta.charset}');`);
}
if (meta.collate) {
code.push(`${spacing()}table.collate('${meta.collate}');`);
}
}
pushedBuilder = true;
};
@@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as mkdirp from 'mkdirp';
import * as Bluebird from 'bluebird';
import {Wetland, EntityManager, Mapping} from './index';
import {EntityManager, Mapping, Wetland} from './index';
import {FieldOptions} from './Mapping';
export class SnapshotManager {
@@ -348,6 +348,7 @@ export class SnapshotManager {
create.index = toCreate.index;
create.unique = toCreate.unique;
create.foreign = toCreate.foreign || [];
create.meta = {};
create.fields = Reflect.ownKeys(toCreate.fields)
.filter(field => !toCreate.fields[field].relationship)
.map(field => {
@@ -356,6 +357,14 @@ export class SnapshotManager {
return toCreate.fields[field];
});
if (toCreate.entity.charset) {
create.meta.charset = toCreate.entity.charset;
}
if (toCreate.entity.collate) {
create.meta.collate = toCreate.entity.collate;
}
if (!toCreate.relations) {
return;
}
@@ -455,6 +464,7 @@ export class SnapshotManager {
function getCreateInstructions(create, table) {
if (!create[table]) {
create[table] = {
meta : {},
foreign: [],
index : {},
unique : {},
@@ -13,6 +13,8 @@ export class Product {
public author: User;
static setMapping(mapping) {
mapping.entity({charset: 'utf8mb4', collate: 'utf8mb4_bin'});
mapping.field('id', {type: 'integer'}).primary('id').generatedValue('id', 'autoIncrement');
mapping.field('name', {type: 'string', size: 24});

0 comments on commit d18d9ff

Please sign in to comment.