Closed charlyisidore closed 1 year ago
Thank you for your feedback, I will try to reproduce and confirm this problem in the future. The solution you provided is great. If possible, you can submit a PR according to this idea. After I confirm the problem, I can merge it directly.
Many thanks.
I realize that a simpler fix for lib/schema.js (line 75) is to ignore item.dflt_value
and set item.default
to the empty string ''
, as done in think-model-mysql and think-model-postgresql.
It results in letting the native SQLite driver set the default value, which might be a more desirable behavior, and avoids parsing the SQLite syntax.
I plan to submit a PR with this solution.
It has been confirmed locally that there is indeed this problem, thank you very much.
Your issue and problem-solving ideas are very clear and correct, and your understanding of ThinkJS is also in place
think-model-sqlite@1.3.2
released, thanks for your feedback and fix commits.
DESC
I use a SQLite database. I create the following table:
Expected behavior: When I add a
post
to the database without specifying itscontent
value, the defaultcontent
value should be the stringabc
.Actual behavior: Instead, the default value is surrounded by two single quotes (
'abc'
), as shown by the log:ENV
OS Platform: Ubuntu 22.04
Node.js Version: 16.20.1
ThinkJS Version: 3.2.15 (
think-model
: 1.5.4,think-model-sqlite
: 1.3.1)code
how to reproduce
I attached a project zip to this issue.
thinkjs-sqlite-issue.zip
To reproduce the bug, create the SQLite database:
Run the server:
Access
http://localhost:8360/
more description
Running
PRAGMA table_info( post )
in SQLite shows:This is where the
'abc'
value comes from.The
'abc'
value is assigned here: https://github.com/thinkjs/think-model-sqlite/blob/d6f52a6629b069c6d47f4700c6ad54bed5432421/lib/schema.js#L75It is later passed to
_parseItemSchema()
but the original value'abc'
remains.workaround
The default value can be overridden by creating a file
src/model/post.js
:possible fix
Remove the surrounding quotes from
item.default
in_parseItemSchema()
: https://github.com/thinkjs/think-model-sqlite/blob/d6f52aa6629b069c6d47f4700c6ad54bed5432421/lib/schema.js#L30