Comments (9)
I have the same issue with loopback 3.0.0
from loopback-connector-postgresql.
How did you create the Role table? Do you create the columns for Date type with 'TIMESTAMP WITH TIME ZONE’?
Here is an example SQL for date properties from ‘automigrate’:
CREATE TABLE "public"."account" (
"email" VARCHAR(1024),
"level" INTEGER,
"created" TIMESTAMP WITH TIME ZONE,
"modified" TIMESTAMP WITH TIME ZONE,
"id" SERIAL,
PRIMARY KEY("id")
)
Thanks,
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.
StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.
On Jun 20, 2014, at 5:50 PM, Jonathan [email protected] wrote:
I'm following the instructions for defining an admin role in the documentation, but I'm receiving the following error at the Role.create({name: 'admin'}, cb) step:
loopback:connector:postgresql error: time zone "gmt-0700" not recognized
Any help would be appreciated!—
Reply to this email directly or view it on GitHub.
from loopback-connector-postgresql.
I used automigrate to create the table using the default Role model. The Created and Modified columns are both of type "timestamp with time zone".
It appears the problem is that loopback is trying to insert a javascript date but it needs to be converted to ISO format. Is this an option that I can set somewhere?
from loopback-connector-postgresql.
The conversion is handled by pg
module. I don't have issue with similar code at https://github.com/strongloop-community/loopback-example-database/blob/postgresql/create-test-data.js. What's your Postgresql version?
from loopback-connector-postgresql.
The code sample you provided worked, and after some digging, I think I've narrowed my issue. My Postgresql version is 9.3.4.2.
My problem appears to stem from the defaults set on the Role model timestamps here: https://github.com/strongloop/loopback/blob/master/lib/models/role.js#L14-16
I modified the code sample you provided to recreate the issue.
var app = require('./app');
var dataSource = app.dataSources.accountDB;
var properties = {
email: {type: String},
level: {type: Number},
created: {type: Date, default: Date},
modified: {type: Date, default: Date}
};
var Test = app.model('test', {
properties: properties,
dataSource: 'accountDB'
});
var tests = [
{ email: "[email protected]",
level: 10
}, {
email: "[email protected]",
level: 20
} ];
var count = tests.length;
dataSource.automigrate('test', function (err) {
tests.forEach(function(test) {
Test.create(test, function(err, result) {
if(!err) {
console.log('Record created:', result);
count--;
if(count === 0) {
console.log('done');
}
}
});
});
});
Thanks for your help. Let me know if I can provide any additional info.
from loopback-connector-postgresql.
I'm having the exact same issue as @woodedlawn. I tried to update my loopback-datasource-juggler in order to employ your workaround, @raymondfeng, but I couldn't get a 1.6.x version because of the npm error
npm ERR! peerinvalid The package loopback-datasource-juggler does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants loopback-datasource-juggler@>=1.4.0 <1.6.0
I manually went in and changed loopback's package.json to allow a 1.6.x version of loopback-datasource-juggler, npm installed the latest version, and instead of the time zone error I was met with a new error:
error: null value in column "id" violates not-null constraint
when running the same code from the docs to create a role for a user. So I changed the code to provide an id when creating a new role and role mapping, and it worked. The working code looked like:
User.create({name: 'John', email: '[email protected]', password: 'foobar'}, function (err, user) {
// Create the static admin Role
Role.create({name: 'admin', id: '1'}, function (err, role) {
// Make John an admin
role.principals.create({principalType: RoleMapping.USER, principalId: user.id, id: '1'});
});
Is there a reason the version of loopback I'm using (1.8.8) doesn't want a 1.6.x version of loopback-datasource-juggler, or should this be fixed in its package.json file? And am I missing something or is setting the id when creating a new Role and Role Mapping necessary?
Thanks!!
from loopback-connector-postgresql.
Please upgrade to loopback 1.9.x. Remove node_modules and run npm install if necessary.
Sent from my iPhone 5
On Jul 1, 2014, at 4:55 PM, jlouthan [email protected] wrote:
I'm having the exact same issue as @woodedlawn. I tried to update my loopback-datasource-juggler in order to employ your workaround, @raymondfeng, but I couldn't get a 1.6.x version because of the npm error
npm ERR! peerinvalid The package loopback-datasource-juggler does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants loopback-datasource-juggler@>=1.4.0 <1.6.0I manually went in and changed loopback's package.json to allow a 1.6.x version of loopback-datasource-juggler, npm installed the latest version, and instead of the time zone error I was met with a new error:
error: null value in column "id" violates not-null constraint
when running the same code from the docs to create a role for a user. So I changed the code to provide an id when creating a new role, and it worked. The working code looked like:
User.create({name: 'John', email: '[email protected]', password: 'foobar'}, function (err, user) { // Create the static admin Role Role.create({name: 'admin', id: '1'}, function (err, role) { // Make John an admin role.principals.create({principalType: RoleMapping.USER, principalId: user.id});
});
Is there a reason the version of loopback I'm using (1.8.8) doesn't want a 1.6.x version of loopback-datasource-juggler, or should this be fixed in its package.json file? And am I missing something or is setting the id when creating a new Role necessary?Thanks!!
—
Reply to this email directly or view it on GitHub.
from loopback-connector-postgresql.
Cleaning up old issues, loopbackio/loopback-datasource-juggler@3edee5c address this issue, closing issue now.
from loopback-connector-postgresql.
For me the problem was in setting updatedAt to number. Changed to Date object.
Model.observe('before save', function (ctx, next) {
var instance = ctx.instance || ctx.data;
// instance.updatedAt = Date.now();
instance.updatedAt = new Date();
next();
});
from loopback-connector-postgresql.
Related Issues (20)
- Postgresql column as text[] or character varying() is returning data as string HOT 8
- Query with AND & OR combination is not working HOT 2
- Error when using transaction timeout HOT 6
- Postgres support > 9.x HOT 4
- LB4 with [email protected] causing SSL Error HOT 4
- eq object (JSON columns) doesn't work HOT 6
- Error: syntax error at or near ")"
- Support for Full Text Search
- Option to use joins instead of multiple calls for relations. HOT 1
- Release called on client which has already been released to the pool HOT 2
- Doesn't scramble the where correctly
- If url is empty string in config server crashes HOT 2
- Dependency Dashboard
- Add back Node.js v12 tests HOT 4
- Support bulk insert in one query using newly added createAll() in connector
- Error: Postgresql column as jsonb returning data as string using createAll() method HOT 2
- MongoDB extended operator rules erroneously applied to SQL databases and json bodies
- Default values in Models properties totally being ignored when using migrateschema. HOT 1
- Support for overlaps json operator
- Getting 5000ms Timeout error while connecting Postgres - I'm using node version 16.0.0, still running into the same problem. And I'm using the latest Postgres connector: `^7.0.1`. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-connector-postgresql.