Skip to content

Commit f53e91f

Browse files
committed
Convert primary keys to UUID string
1 parent 759592a commit f53e91f

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/entity/MarkovOptions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column, OneToOne } from 'typeorm';
1+
import { Entity, BaseEntity, Column, OneToOne, PrimaryColumn, Generated } from 'typeorm';
22
import { MarkovRoot } from './MarkovRoot';
33

44
@Entity()
55
export class MarkovOptions extends BaseEntity {
6-
@PrimaryGeneratedColumn()
7-
id: number;
6+
@PrimaryColumn({ type: 'text' })
7+
@Generated('uuid')
8+
id: string;
89

910
@Column()
1011
stateSize: number;

src/entity/MarkovRoot.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import {
22
Entity,
33
BaseEntity,
44
OneToOne,
5-
PrimaryGeneratedColumn,
65
OneToMany,
76
JoinColumn,
8-
ValueTransformer,
7+
PrimaryColumn,
8+
Generated,
99
} from 'typeorm';
1010
import { MarkovCorpusEntry } from './MarkovCorpusEntry';
1111
import { MarkovFragment } from './MarkovFragment';
1212
import { MarkovOptions } from './MarkovOptions';
1313

1414
@Entity()
1515
export class MarkovRoot extends BaseEntity {
16-
@PrimaryGeneratedColumn()
17-
id: number;
16+
@PrimaryColumn({ type: 'text' })
17+
@Generated('uuid')
18+
id: string;
1819

1920
@OneToMany(() => MarkovCorpusEntry, (entry) => entry.markov, { nullable: true })
2021
corpus: MarkovCorpusEntry[];

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type MarkovConstructorOptions = {
2323
/**
2424
* Used to set the options database ID manually
2525
*/
26-
id?: number;
26+
id?: string;
2727

2828
/**
2929
* The stateSize is the number of words for each "link" of the generated sentence.
@@ -38,7 +38,7 @@ export type MarkovConstructorProps = {
3838
/**
3939
* Used to set a root database ID manually
4040
*/
41-
id?: number;
41+
id?: string;
4242

4343
/**
4444
* Global Markov corpus generation options
@@ -109,7 +109,7 @@ export default class Markov {
109109

110110
public options: MarkovOptions | MarkovDataMembers;
111111

112-
public id: number;
112+
public id: string;
113113

114114
private defaultOptions: MarkovDataMembers = {
115115
stateSize: 2,
@@ -150,7 +150,7 @@ export default class Markov {
150150
}
151151

152152
private construct() {
153-
this.id = this.constructorProps?.id || 1;
153+
this.id = this.constructorProps?.id || '1';
154154

155155
// Save options
156156
this.options = Object.assign(this.defaultOptions, this.constructorProps?.options);

test/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('Markov class', () => {
195195
});
196196

197197
it('should export the original database values', async () => {
198-
markov = new Markov();
198+
markov = new Markov({ id: '1', options: { id: '1' } });
199199
connection = await createConnection();
200200
await markov.addData(data);
201201

test/v4-export.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": 1,
2+
"id": "1",
33
"corpus": [
44
{
55
"id": 1,
@@ -664,7 +664,7 @@
664664
}
665665
],
666666
"options": {
667-
"id": 1,
667+
"id": "1",
668668
"stateSize": 2
669669
}
670670
}

0 commit comments

Comments
 (0)