Where and how can I view a generated database query - strapi

I have a small question:
Where and how can I view a generated database query, via "Debug" or "Strapi.log.info(...)"?
Many greetings

You can in you config/environments/development/database.json file into the options object add the following "debug": true
You will be able to see all the database requests.
eg. for a SQLite database connection
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "bookshelf",
"settings": {
"client": "sqlite",
"filename": ".tmp/data.db"
},
"options": {
"useNullAsDefault": true,
"debug": true
}
}
}
}

Related

Elasticsearch alias not being created on index creation

I'm using the go-elasticsearch API in my application to create indices in an Elastic.co cloud cluster. The application dynamically creates an index with a template and then starts indexing documents. The template includes an alias name and look like this:
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"title": {
"type": "text"
},
"created_at": {
"type": "date"
},
"updated_at": {
"type": "date"
},
"status": {
"type": "keyword"
}
}
},
"aliases": {
"rollout-nodes-f0776f0": {}
}
}
The name of the alias can change, so we pass it to the template when we create a new index. This is done with the Create indices API in Go:
indexTemplate := getIndexTemplate()
res, err := n.client.Indices.Create(
indexName,
n.client.Indices.Create.WithBody(indexTemplate),
n.client.Indices.Create.WithContext(ctx),
n.client.Indices.Create.WithTimeout(time.Second),
)
Doing some testing, this code works on localhost (without security enabled) but is not working with the cluster in Elastic.co, the index is created but not the alias.
I think it should be a problem related with either the API Key permissions or some configuration in the server, but I was unable to find yet which permission I'm missing.
For more context, this is the API Key I'm using:
{
"id": "fakeID",
"name": "index-service-key",
"creation": 1675350573126,
"invalidated": false,
"username": "fakeUser",
"realm": "cloud-saml-kibana",
"metadata": {},
"role_descriptors": {
"logstash_writer": {
"cluster": [
"monitor",
"transport_client",
"read_ccr",
"read_ilm",
"manage_index_templates"
],
"indices": [
{
"names": [
"*"
],
"privileges": [
"all"
],
"allow_restricted_indices": false
}
],
"applications": [],
"run_as": [],
"metadata": {},
"transient_metadata": {
"enabled": true
}
}
}
}
Any ideas? I know I can use the POST _aliases API, but the index creation option should be working too.

How to change the local payload when invoking a lambda in cloud9 IDE?

I'm developing in AWS Cloud9, and have a basic "Hello, World" API set up using Lambda.
Now I would like to iterate so that the API can accept parameters. Cloud9 used to have a convenient UI for modifying the payload when running "local" (in the IDE, without deploy). But I can't find where this has been moved, and the documentation still references the previous UI.
To test this, I've included a simple print(event) in my Lambda, and started modifying various components. So far I only print an empty dict ({}).
I suspect it's in the launch.json but so far everything I've modified has not been picked up. Showing below
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "API token-to-geojson:HelloWorldFunction (python3.9)",
"invokeTarget": {
"target": "api",
"templatePath": "token-to-geojson/template.yaml",
"logicalId": "HelloWorldFunction"
},
"api": {
"path": "/hello",
"httpMethod": "get",
"payload": {
"json": {}
}
},
"lambda": {
"runtime": "python3.9"
}
},
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "token-to-geojson:HelloWorldFunction (python3.9)",
"invokeTarget": {
"target": "template",
"templatePath": "token-to-geojson/template.yaml",
"logicalId": "HelloWorldFunction"
},
"lambda": {
"payload": {
"ticky": "tacky"
},
"environmentVariables": {},
"runtime": "python3.9"
}
}
]
}
The only thing I saw is we need to add "json" before the actual json data. In the example below, it appears the IDE already knows the id is event.id (note event is the first argument of the handler).
"lambda": {
"payload": {
"json": {
"id": 1001
}
},
"environmentVariables": {}
}

Parse server - get related classes - rest api

Assuming i have a class User and a class Profile
The profile class has a field called "sex" and a field called "user" which is a pointer to user class.
If i get the profile endpoint with : https://myapi.back4app.io/classes/Profile i can get the Profile object:
{
"results": [
{
"objectId": "sIE6lOZP7R",
"user": {
"__type": "Pointer",
"className": "_User",
"objectId": "asP3EFYSR4"
},
"sex": "male",
"createdAt": "2020-05-25T17:15:49.324Z",
"updatedAt": "2020-05-25T17:15:49.324Z"
}
]
}
and if i want to include the user of this profile, i can include with: https://myapi.back4app.io/classes/Perfil?include=user so i get:
{
"results": [
{
"objectId": "sIE6lOZP7R",
"user": {
"objectId": "asP3EFYSR4",
"username": "fabiojansen",
"createdAt": "2020-05-25T17:15:16.273Z",
"updatedAt": "2020-05-25T17:15:16.273Z",
"ACL": {
"*": {
"read": true
},
"asP3EFYSR4": {
"read": true,
"write": true
}
},
"__type": "Object",
"className": "_User"
},
"sex": "male",
"createdAt": "2020-05-25T17:15:49.324Z",
"updatedAt": "2020-05-25T17:15:49.324Z"
}
]
}
Its ok, but if i want to get all the users, with the profile information in one query? Its possible? In my User class, i dont have any pointer to Profile class, only in profile class.
Is there any way?
Thanks
You have several options:
1) You can use an aggregate pipeline and $lookup the user in the Perfil class which performs a LEFT JOIN. However, this will not return an array of Parse.Object, you'd have to parse the results manually. From the docs:
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
2) You can do 2 requests by first getting all the users and then getting all their profiles by user IDs.
3) You can change your data model and add a pointer to Perfil in your User class. If you are running this query at scale it may be beneficial.

Strapi mongodd de-populate

Is there any way to prevent a call like this strapi.services.MODEL_NAME.find(query) from populating its relations?
In my specific case I have a simple Message model:
"attributes": {
"body": {
"type": "string",
"minLength": 1,
"required": true,
"maxLength": 300
},
"chat": {
"model": "chat"
},
"user": {
"model": "user",
"plugin": "users-permissions"
}
}
and in a particular case I wish not to populate user & chat, just reference their IDs.
I believe in my case the solution would be to add an empty array:
strapi.services.MODEL_NAME.find(query, [])
You can add autoPopulate option to false.
"user": {
"model": "user",
"plugin": "users-permissions",
"autoPopulate": false
}

OrientDB ETL with self joined mysql table

I'm trying (new to OrientDb) to load my old fashioned self joined mysql table to OrientDb.
I'm kinda stuck, I want to create vertices and edges with ETL but edges are created to empty vertices. I spent many hours in the documentation but can't find what I am missing.
Here is my oetl json file :
{
"config": {
"log": "debug"
},
"extractor" : {
"jdbc": { "driver": "com.mysql.jdbc.Driver",
"url": "***",
"userName": "***",
"userPassword": "***",
"query": "select nid, pnid, label from prod_arbo limit 500" }
},
"transformers" : [
{ "vertex": { "class": "Noeud", "skipDuplicates": true} },
{ "field": { "fieldName": "titre", "expression": "label"}},
{ "field": { "fieldName": "titre", "operation": "remove"} },
{ "field": { "fieldName": "pnid", "operation": "remove"} },
{ "edge": {
"class": "Parent",
"joinFieldName": "pnid",
"lookup": "Noeud.nid",
"unresolvedLinkAction": "CREATE"
} }
],
"loader" : {
"orientdb": {
"dbURL": "***",
"dbUser": "***",
"dbPassword": "***",
"standardElementConstraints": false,
"tx": false,
"wal": false,
"dbType": "graph"
}
}
}
Mysql db is like :
nid -> autoincrement unique id
label -> need to put this in field "titre"
pnid -> parent self join
I get logs like this :
[43:edge] DEBUG Transformer input: v(Noeud)[#13:57377]
[43:edge] DEBUG joinCurrentValue=null, lookupResult=null
[43:edge] DEBUG created new vertex=Noeud#13:57378{nid:null} v36
[43:edge] DEBUG created new edge=e[#17:56380][#13:57377-Parent->#13:57378]
[43:edge] DEBUG Transformer output: v(Noeud)[#13:57377]
And I don't understand why nid is null on new created vertex while created edge, how can I do to make it use pnid field here ?
Many thanks for your help
Laurent

Resources