From 6f98448006a5d1d2fc884405d36a7d8f9f432d95 Mon Sep 17 00:00:00 2001 From: Taras Date: Fri, 26 Aug 2022 23:00:35 +0200 Subject: [PATCH] bugfix --- src/classes/Instance.ts | 7 +++- src/interfaces/Document.ts | 2 -- tests/userInitiale.ts | 66 ++++++++++++++++++++++---------------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/classes/Instance.ts b/src/classes/Instance.ts index bae2d36..de7a731 100644 --- a/src/classes/Instance.ts +++ b/src/classes/Instance.ts @@ -46,8 +46,11 @@ export class Instance { const table = this.getTable() if (this._options.isNew) { + const _id = this._fields._id || crypto.randomUUID() + new ColumnsUtils(this._schema.columns, table, this._fields) - table.push({...this._fields, _id: this._fields._id || crypto.randomUUID()}) + table.push({...this._fields, _id}) + this._fields._id = _id this.writeTable([...table]) } else { @@ -57,5 +60,7 @@ export class Instance { this.writeTable([...filteredTable]) } + + return this } } diff --git a/src/interfaces/Document.ts b/src/interfaces/Document.ts index d600bc7..c3aeea8 100644 --- a/src/interfaces/Document.ts +++ b/src/interfaces/Document.ts @@ -1,5 +1,3 @@ export interface Document { _id: string - _tableName: string - _url: string } diff --git a/tests/userInitiale.ts b/tests/userInitiale.ts index 5e0b4e7..862f14b 100644 --- a/tests/userInitiale.ts +++ b/tests/userInitiale.ts @@ -2,33 +2,45 @@ import {Column, Document, Model, Schema, TinyTable} from "../tinydb.ts" @TinyTable("users") class User { - @Column({ - type: "string", - unique: true - }) - name!: string - - @Column({ - type: "date" - }) - birthday!: string - - @Column({ - type: "boolean", - default: false, - allowNull: true - }) - isAdmin!: boolean - - @Column({ - allowNull: true, - type: "json", - default: { - theme: "light", - lang: "en" - } - }) - settings!: Record + @Column({ + type: "string", + unique: true + }) + name!: string + + @Column({ + type: "date" + }) + birthday!: string + + @Column({ + type: "boolean", + default: false, + allowNull: true + }) + isAdmin!: boolean + + @Column({ + allowNull: true, + type: "json", + default: { + theme: "light", + lang: "en" + } + }) + settings!: Record + + // @Column({ + // allowNull: true, + // default: [], + // type: "model" + // }) + // friends!: string[] + + // @Column({ + // type: "model" + // }) + // profile!: User } export type userDocument = User & Document