Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarasikee committed Aug 26, 2022
1 parent b359f91 commit 6f98448
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
7 changes: 6 additions & 1 deletion src/classes/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class Instance<T extends { _id: string }> {
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 {
Expand All @@ -57,5 +60,7 @@ export class Instance<T extends { _id: string }> {

this.writeTable([...filteredTable])
}

return this
}
}
2 changes: 0 additions & 2 deletions src/interfaces/Document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export interface Document {
_id: string
_tableName: string
_url: string
}
66 changes: 39 additions & 27 deletions tests/userInitiale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>
@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<string, unknown>

// @Column({
// allowNull: true,
// default: [],
// type: "model"
// })
// friends!: string[]

// @Column({
// type: "model"
// })
// profile!: User
}

export type userDocument = User & Document
Expand Down

0 comments on commit 6f98448

Please sign in to comment.