Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple-json column type #1488

Merged
merged 2 commits into from
Jan 23, 2018
Merged

simple-json column type #1488

merged 2 commits into from
Jan 23, 2018

Conversation

idchlife
Copy link
Contributor

No description provided.

@idchlife
Copy link
Contributor Author

idchlife commented Jan 22, 2018

I'm experiencing as I can guess abnormal test fail with sqlite on my local system. I cannot distinguish is it my fault or I pulled from master WIP with failing test.

  sqljs driver > autosave
    1) should call autoSaveCallback on insert, update and delete


  117 passing (52s)
  4 pending
  1 failing

  1) sqljs driver > autosave should call autoSaveCallback on insert, update and delete:

      AssertionError: expected 0 to equal 7
      + expected - actual

      -0
      +7

      at Object.<anonymous> (test/functional/sqljs/auto-save.ts:55:29)
      at step (build/compiled/test/functional/sqljs/auto-save.js:32:23)
      at Object.next (build/compiled/test/functional/sqljs/auto-save.js:13:53)
      at fulfilled (build/compiled/test/functional/sqljs/auto-save.js:4:58)
      at <anonymous>

edit: well, since CI tests have passed I can assume that's problem with my sqlite or something

@@ -174,6 +174,14 @@ export class DateUtils {
return value;
}

static simpleJsonToString(value: any): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date Utils? 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@19majkel94 I looked at simpleArrayToString, discovered that it was odd for it to be in DateUtils, but well, my PR is as simple as it gets, so I did the same thing 😢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so we will leave it for now and later it would be refactored 😉

@MichalLytek
Copy link
Contributor

Looks like a lot of copy-paste - isn't there any generic driver when we could implement simple-json once?

BTW, I think that it would be nice if we support subentities in this case - using class type instead of inline object type. So any additional props not mapped to the class field would be stripped. This is how it work with Mongo, right? 😕

@idchlife
Copy link
Contributor Author

@19majkel94 yes, copy-paste because it kinda copies functionality of simple-array. JSON.stringify and JSON.parse and that's all.

What do you mean by subentities? It's just a simple field for json, no?

@MichalLytek
Copy link
Contributor

MichalLytek commented Jan 22, 2018

@idchlife Some kind of embedded entities:
http://typeorm.io/#/embedded-entities

Of course it wouldn't create columns like the normal one - the use case is just for stripping of additional props doesn't matching to the schema like with document databases and ODMs.

@idchlife
Copy link
Contributor Author

@19majkel94 ah, you mean this is basically an embedded entity but simplified. And also JSON.stringify and JSON.parse can be used with embedded entities, if database supports json - it uses json type, if not - "text"-y type, yes?

It will be a nice addition I agree with you, but simple-json is like for any kind of data you want to save in json. In my case I tried to save data about position (x, y). It seems simple with embedded entities, but I've got sqlite for local usage and postgres for backend usage. I will be using same TS types but in postgres I will have not appended columns as in embedded entities, but jsonb. And it's convenient to have json in jsonb/text and not additional columns.

I think simple-json is good as it is right now.

@pleerock
Copy link
Member

I'm experiencing as I can guess abnormal test fail with sqlite on my local system. I cannot distinguish is it my fault or I pulled from master WIP with failing test.

can you please check if your local ormconfig.json sqljs section matches with ormconfig.json.dist (no extra options like autoSave in there)

@@ -300,6 +300,34 @@ just like you stored them.

Note you **MUST NOT** have any comma in values you write.

### `simple-json` column type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to put quick link in the header to a new sectionl.

@pleerock
Copy link
Member

@idchlife PR looks good, thank you very much. Please add changelog for the next 0.1.x version as well and this PR can be merged I believe.

@idchlife
Copy link
Contributor Author

@pleerock updated PR. about sqljs - ormconfig.json is exact copy of ormconfig.json.dist (well, without comma at the end, because of comma in ormconfig.json.dist at the end it's hard to understand what's wrong at the first, if just copy-rename file, error in tests is that ormconfig.json does not exist but actually there comma which breaks json), so I don't quiet understand what's the problem :(

@pleerock
Copy link
Member

try to remove "autoSave": false from your local ormconfig file I think it will solve the issue.

@pleerock pleerock merged commit 82b1410 into typeorm:master Jan 23, 2018
@pleerock
Copy link
Member

I have merged this PR, thank you for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants