mysql fulltext index base support(#285)

This commit is contained in:
kononnable 2021-01-01 01:58:50 +01:00
parent 3e29544063
commit 7cae89a9ef
6 changed files with 30 additions and 5 deletions

View File

@ -408,9 +408,7 @@ export default abstract class AbstractDriver {
.forEach((col) => {
// eslint-disable-next-line no-param-reassign
col.primary = true;
if (
col.options.unique
) {
if (col.options.unique) {
delete col.options.unique;
}
});

View File

@ -328,8 +328,9 @@ export default class MysqlDriver extends AbstractDriver {
ColumnName: string;
is_unique: number;
is_primary_key: number;
is_fulltext: number;
}>(`SELECT TABLE_NAME TableName,INDEX_NAME IndexName,COLUMN_NAME ColumnName,CASE WHEN NON_UNIQUE=0 THEN 1 ELSE 0 END is_unique,
CASE WHEN INDEX_NAME='PRIMARY' THEN 1 ELSE 0 END is_primary_key
CASE WHEN INDEX_NAME='PRIMARY' THEN 1 ELSE 0 END is_primary_key, CASE WHEN INDEX_TYPE="FULLTEXT" THEN 1 ELSE 0 END is_fulltext
FROM information_schema.statistics sta
WHERE table_schema IN (${MysqlDriver.buildEscapedObjectList(
dbNames
@ -351,6 +352,8 @@ export default class MysqlDriver extends AbstractDriver {
options: {},
};
if (records[0].is_primary_key === 1) indexInfo.primary = true;
if (records[0].is_fulltext === 1)
indexInfo.options.fulltext = true;
if (records[0].is_unique === 1) indexInfo.options.unique = true;
records.forEach((record) => {

View File

@ -3,6 +3,7 @@ export type Index = {
columns: string[];
options: {
unique?: boolean;
fulltext?: boolean;
};
primary?: boolean;
};

View File

@ -0,0 +1,13 @@
import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } from "typeorm";
@Index("my_index", ["title"], { fulltext: true })
@Entity("Post")
export class Post {
@PrimaryGeneratedColumn()
id: number;
@Column("varchar")
title: string;
}

View File

@ -199,10 +199,15 @@ function runTestForMultipleDrivers(
case "248":
return dbDrivers.filter(dbDriver =>
dbDriver === "postgres"
);case "273":
);
case "273":
return dbDrivers.filter(dbDriver =>
["mysql", "mariadb","mssql"].includes(dbDriver)
);
case "285":
return dbDrivers.filter(dbDriver =>
["mysql", "mariadb"].includes(dbDriver)
);
default:
return dbDrivers;
}

View File

@ -27,6 +27,8 @@ class EntityIndex {
public columnNames: string[] = [];
public isUnique = false;
public fulltext = false;
}
function removeTrailingComas(input: string) {
@ -208,6 +210,9 @@ export default class EntityFileToJson {
ind.isUnique =
optionsStr.split(":")[1].trim() === "true";
break;
case "fulltext":
ind.fulltext = optionsStr.split(":")[1].trim() === "true";
break;
default:
console.log(
`[EntityFileToJson:convert] Index option not recognized ${ind.indexName}:`