Prisma client returns undefined - orm

I'm new to using the Prisma client (With NodeJS & Postgres) and have hit an issue similar to this question, but the answer doesn't fix the issue for me.
I'm seeing that the Prisma client correctly generates the SQL for my queries, but always seems to return undefined.
Example:
const result = await this.databaseService.venue.findFirst({
where: venueWhereUniqueInput,
include: {
bookingProvider: true,
},
});
Since the SQL is correct and I have manually run the SQL to check records are returned, I can only assume there's an issue with Prisma mapping the results to my model.
I have tried the following:
Checked if there's any outstanding migrations:
npx prisma migrate dev --name name_of_stuff
npx prisma migrate dev
Generated the Primsa models (Typescript generated models look correct)
npx prisma generate
Turned on verbose logging to check for any errors
export DEBUG="*"
But alas, I keep getting undefined results, please can someone advise how this can be resolved, many thanks!
Prisma version: "prisma": "^3.5.0",

Related

async-storage SyntaxError Unexpected identifier while transpiling with Babel7

After using #react-native-community/async-storage and transpile it with the following npm command in my react-native environment.
"test": "NODE_ENV=test ./node_modules/.bin/mocha --timeout 5000 --require #babel/register \"./src/shared/__tests__/**/*.spec.js\""
I did some research and in no vain. But I found it happens to Jest too.
jest test fails after installing react-native-async-storage
this is my babel.config.js
module.exports = {
env: {
production: {
},
test: {
presets: [
'#babel/preset-env'
],
},
},
};
I'm only testing non-jsx code only so #babel/preset-env seems to be working alright.
node_modules/#react-native-community/async-storage/lib/index.js:5
import AsyncStorage from './AsyncStorage';
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
It seems like no one likes to answer jest newbie questions....
anyway, when starting to learn jest, I encountered some funny error messages that doesn't reflect the actual error. There are some possible situations a developer can consider.
You didn't to mock your module say A_module that is inside node_modules so one of the modules say B_modules inside A_modules uses a NativeModules from react so Jest cannot performa a test. Please look at stack trace or use a debugger to find out which one you prefer to mock.
Mock a module that uses NativeModules (similar to point 1, but more direct and concise )
You need to understand jest more thoroughly before you proceed. Reading documentation is good but jump to example when you think fit. especially check out the examples that you really need and read related ones. Many of the time, either your Babel setting or mocking methods is incorrect.
use jest.mock instead of jest.genMockFromModule. Why? there are some functions or init function that causes your test to crash at this statement. Because it calls NativeModules or something jest doesn't allow. use mock instead.
Solutions to this question: please refer to this most updated solution.
thanks

firebase-admin - Auth error:TypeError: URL is not a constructor

I've got a node API that uses firebase-admin to handle firestore data. This wasn't a problem till a few days ago and now it started happening.
The weird thing is, I only seem to get this on my production server and not on local development environment(even using the same database).
I've tried redeploying, restarting the server, checked database configuration and everything and nothing really worked.
This is one of the more detailed errors:
Error: 14 UNAVAILABLE: Getting metadata from plugin failed with error: URL is not a constructor
at Object.exports.createStatusError (/root/apps/api/src/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:845:24)
And this is my connection file:
import * as admin from 'firebase-admin'
import serviceAccount from './fbAdminKey'
admin.initializeApp({
projectId: '<myProjectId>',
credential: admin.credential.cert(serviceAccount),
databaseURL: '<myDbURL>'
})
const db = admin.firestore()
const messaging = admin.messaging()
const auth = admin.auth()
export default { db, messaging, auth }
It should be able to just connect to the database and do the operations, I have an app, a web application and they all work normally, just the node API seems to be acting weirdly.
So, after banging my head around for nearly a week, having other problems and stuff, I could figure it out with the help of everybody here.
The problem was the node.js version
I was running node 8.4.0 locally and node 6.x.x on production. (firebase-admin 7.0.0)
So I updated it on production using nvm and than got another problem, related to the grpc version. I had a newer version installed and it was requiring an older one.
Note
If you are using PM2, make sure to update it as well:
http://pm2.keymetrics.io/docs/usage/update-pm2/
After that it started working again and it stuff is back on track.
Not the exact solution because it doesn't solve the problem with Node 6.11.5.
The production server runs by default on Node 6.11.5 and if you wanted to change the runtime version to 8, then refer to this article.
https://firebase.google.com/docs/functions/manage-functions#set_runtime_options
However, keep in mind that this runtime version is currently in beta, so it might break.
I also noticed, that I was able to get rid of this error that you were facing by installing previous version of firebase-admin (6.2.0 to be specific, as for now - the version 7.x.x is the latest one).
I'm afraid that one of the newer firebase-admin versions broke this feature in some environments and that's why this issue is not that common.

How to use JestJS with a database?

I am working on a new project using Jest, Express and Sequelize to create an API.
I have some endpoints working, and am writing tests for each of my endpoints.
Coming from the Ruby on Rails world, I am used to writing tests where the database is cleaned between every test.
This seems to be impossible in Jest because there does not appear to be a way to not have tests clobber the database since they are all running in parallel
With that in mind, I created this global beforeAll function in tests/support/setup.js and configured Jest to use this method before all my specs run:
// package.json
{...
"jest": {
"setupFilesAfterEnv": [
"<rootDir>/tests/support/setup.js"
]
}
}
// tests/support/setup.js
import models from '../../db/models'
global.beforeAll(async () => {
await models.sequelize.drop()
await models.sequelize.sync()
})
But it looks like this doesn't work either, but I think this is actually running the beforeAll method before each test suite....so the database still gets clobbered.
Right now, Jest seems useless to me when used with a database. Am I missing something?
What are some methods for using Jest with a database where each test is run with a pristine database?

Using imports instead of require's in ExpressJS with Webpack and Babel

I have been following this set of tutorials, in which the writer uses import instead of require. Unfortunately, when I do this it doesn't work. I am using babel-preset-env instead of the stage-0 and babel-preset-es2015 presets used in the tutorial. I am also using yarn instead of npm.
babel-node ..., works fine, however, when I use node ... I get errors saying unexpected token import. I can't use babel-node in production, so I am trying to solve this issue now.
What is the correct way to do this? It is too much code to post here so here is a link to the git repo: https://github.com/mjhough/react-express-sample

How do you spin up a new spine app using the spine.app cli?

I'm attempting to use the spine.app cli and I'm encountering a couple of errors and I'm uncertain what the root cause actually is.
The guide found at: http://spinejs.com/docs/started gives these steps
spine app my-app
cd my-app
npm install .
hem server
following these steps, initially yields this error on the terminal:
Cannot find module: es5-shimify. Have you run `npm install .` ?
Investigating, it seems es5-shimify has been deprecated in favor of es5-shim, so my initial inclination was to replace the dependency to es5-shim. So I updated setup.coffee to require('es5-shim'), and I updated the referenced slug.json module and restarted the server. This seems to get me a little further, but still produces an error ( though not in the terminal, instead in the chrome console )
Uncaught TypeError: Property 'jQuery' of object [object Object] is not a function
This appears to be occurring on line 8 of public/index.html. I did some debugging here and it appears that require('jqueryify') is returning undefined, and I'm not certain what the expected result is. Any guidance on the right way to approach this process or perhaps information on what the root issue might be would be greatly appreciated.
Use the latest version try again.
The package.json as following
{
"name": "app",
"version": "0.0.1",
"dependencies": {
"spine": "~1.3.0"
}
}
all others dependencies has been removed,and it works for me.