Turning Raw data into TypeORM Entity
I have data that I am sending to my NodeJs server that is in the standard SQL format with the default SQL column names etc.
I want to take these raw entities and reinsert them into the db. It seems like I can't insert them straight up without converting them into entities, or preparing a raw SQL statement.
I want to turn these values into TypeORM entities automatically without having to write transform functions.
Is there a good way to accomplish this in TypeORM?
See also questions close to this topic
-
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null (SQL: insert into `tbl_studentmains`)
I am getting this error when I pass values from one page to another with the same id from but I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null (SQL: insert into
tbl_studentmains
(id
,Name
,Father_Name
,Student_CNIC
,Father_CNIC
,DOB
,Nationality_ID
,NativeLanguage_ID
,District_ID
,Caste_ID
,Religion_ID
,Marital_Status
,Email
,PresentAddress
,PresentResidingPlace_ID
,PermanentAddress
,StudentContactNoPersonal
,ContactResidence
,Em_name
,Em_Relationship
,Em_Contact
,Em_Residence
,Em_Address
,FG_Occupation_ID
,Monthly_income
,StudentDistinctionYesNo
,Designation
,Name_of_Employer
,EmployerContactNo
,updated_at
,created_at
) values (?, Dilawar Naseem, Shahab Naseem, 5440022939451, 5440022939459, 2021-03-08, Pakistani, Punjabi, Quetta, Sheikh, Islam, Single, dilawarnaseem@yahoo.com, Plot #17 gulbagh, Quetta, Plot #17 gulbagh, 03318042227, 03318042227, Shahab Naseem, Father, 03337826049, 0812872038, Plot #17 gulbagh, Father, 5000, Yes, Intern, Dilawar Naseem, 08122315, 2021-03-08 05:57:26, 2021-03-08 05:57:26))here is my Controller:
<?php namespace App\Http\Controllers; use Validator; use App\Models\tbl_studentmains; use App\Models\tbl_studenteducations; use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; class StudentMainController extends Controller { public function StudentMain(Request $request) { $tbl_studentmains = new tbl_studentmains; $tbl_studentmains->id = $request->id; $tbl_studentmains->Name = $request->Name; $tbl_studentmains->Father_Name = $request->Father_Name; $tbl_studentmains->Student_CNIC = $request->Student_CNIC; $tbl_studentmains->Father_CNIC = $request->Father_CNIC; $tbl_studentmains->DOB = $request->DOB; $tbl_studentmains->Nationality_ID = $request->Nationality_ID; $tbl_studentmains->NativeLanguage_ID = $request->NativeLanguage_ID; $tbl_studentmains->District_ID = $request->District_ID; $tbl_studentmains->Caste_ID = $request->Caste_ID; $tbl_studentmains->Religion_ID = $request->Religion_ID; $tbl_studentmains->Marital_Status = $request->Marital_Status; $tbl_studentmains->Email = $request->Email; $tbl_studentmains->PresentAddress = $request->PresentAddress; $tbl_studentmains->PresentResidingPlace_ID = $request->PresentResidingPlace_ID; $tbl_studentmains->PermanentAddress = $request->PermanentAddress; $tbl_studentmains->StudentContactNoPersonal = $request->StudentContactNoPersonal; $tbl_studentmains->ContactResidence = $request->ContactResidence; $tbl_studentmains->Em_name = $request->Em_name; $tbl_studentmains->Em_Relationship = $request->Em_Relationship; $tbl_studentmains->Em_Contact = $request->Em_Contact; $tbl_studentmains->Em_Residence = $request->Em_Residence; $tbl_studentmains->Em_Address = $request->Em_Address; $tbl_studentmains->FG_Occupation_ID = $request->FG_Occupation_ID; $tbl_studentmains->Monthly_income = $request->Monthly_income; $tbl_studentmains->StudentDistinctionYesNo = $request->StudentDistinctionYesNo; $tbl_studentmains->Designation = $request->Designation; $tbl_studentmains->Name_of_Employer = $request->Name_of_Employer; $tbl_studentmains->EmployerContactNo = $request->EmployerContactNo; $rules = [ 'Name' => 'required|string', 'Father_Name' => 'required|string', 'Student_CNIC' =>'required|numeric', 'Father_CNIC' =>'required|numeric', 'DOB' =>'required|string', 'Nationality_ID' => 'required|string', 'NativeLanguage_ID' => 'required|string', 'District_ID' => 'required|string', 'Caste_ID' => 'required|string', 'Religion_ID' => 'required|string', 'Marital_Status' => 'required|string', 'Email' => 'required|email', 'PresentAddress' => 'required|string', 'PresentResidingPlace_ID' => 'required|string', 'PermanentAddress' => 'required|string', 'StudentContactNoPersonal' => 'required|numeric', 'ContactResidence' => 'required|numeric', 'Em_name' => 'required|string', 'Em_Relationship' => 'required|string', 'Em_Contact' =>'required|numeric', 'Em_Residence' =>'required|numeric', 'Em_Address' =>'required|string', 'FG_Occupation_ID' => 'required|string', 'Monthly_income' => 'required|numeric', 'StudentDistinctionYesNo' => 'required|string', 'Designation' => 'required|string', 'Name_of_Employer' => 'required|string', 'EmployerContactNo' => 'required|numeric', ]; $this->validate($request, $rules); $tbl_studentmains->save(); session()->put('id',$tbl_studentmains->id); return view ('/StudentEducation_form',compact('tbl_studentmains')); } public function StudentEducation(Request $request) { $tbl_studenteducations = new tbl_studenteducations; $tbl_studenteducations->ExaminationPassed_ID = $request->ExaminationPassed_ID; $tbl_studenteducations->SchoolCollege_ID = $request->SchoolCollege_ID; $tbl_studenteducations->Board_University_ID = $request->Board_University_ID; $tbl_studenteducations->RegistrationNo = $request->RegistrationNo; $tbl_studenteducations->Year = $request->Year; $tbl_studenteducations->AnnualSupplementary = $request->AnnualSupplementary; $tbl_studenteducations->RollNo = $request->RollNo; $tbl_studenteducations->MarksObtained = $request->MarksObtained; $tbl_studenteducations->TotalMarks = $request->TotalMarks; $tbl_studenteducations->Subject_ID = $request->Subject_ID; $tbl_studenteducations->std_id = session()->get('id'); $tbl_studenteducations->save(); $tbl_studenteducations = tbl_studenteducations::all(); return view ('/StudentEducation_form',compact('tbl_studenteducations')); } public function index(Request $request) { $tbl_studenteducations = tbl_studenteducations::all(); return view ('/StudentEducation_form',compact('tbl_studenteducations')); } }
Please suggest any solution
-
mysqli cannot use ssh tunnel
I have created an ssh tunnel the following way to connect to my remote db:
admin@admin-VirtualBox:~$ ssh -v -v -v root@xx.xx.xxx.xxx -CNL 13306:localhost:3306 OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug2: resolving "xx.xx.xxx.xxx" port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to xx.xx.xxx.xxx [xx.xx.xxx.xxx] port 22. debug1: Connection established. debug1: identity file /home/admin/.ssh/id_rsa type 0 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/admin/.ssh/id_ed25519-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000 debug2: fd 3 setting O_NONBLOCK debug1: Authenticating to xx.xx.xxx.xxx:22 as 'root' debug3: hostkeys_foreach: reading file "/home/admin/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file /home/admin/.ssh/known_hosts:1 debug3: load_hostkeys: loaded 1 keys from xx.xx.xxx.xxx debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 debug3: send packet: type 20 debug1: SSH2_MSG_KEXINIT sent debug3: receive packet: type 20 debug1: SSH2_MSG_KEXINIT received debug2: local client KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: zlib@openssh.com,zlib,none debug2: compression stoc: zlib@openssh.com,zlib,none debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug2: peer server KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256 debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none,zlib@openssh.com debug2: compression stoc: none,zlib@openssh.com debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com debug3: send packet: type 30 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug3: receive packet: type 31 debug1: Server host key: ecdsa-sha2-nistp256 SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaa debug3: hostkeys_foreach: reading file "/home/admin/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file /home/admin/.ssh/known_hosts:1 debug3: load_hostkeys: loaded 1 keys from xx.xx.xxx.xxx debug1: Host 'xx.xx.xxx.xxx' is known and matches the ECDSA host key. debug1: Found key in /home/admin/.ssh/known_hosts:1 debug3: send packet: type 21 debug2: set_newkeys: mode 1 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug3: receive packet: type 21 debug1: SSH2_MSG_NEWKEYS received debug2: set_newkeys: mode 0 debug1: rekey after 134217728 blocks debug2: key: /home/admin/.ssh/id_rsa (0x55ba671d36b0), agent debug2: key: /home/admin/.ssh/id_dsa ((nil)) debug2: key: /home/admin/.ssh/id_ecdsa ((nil)) debug2: key: /home/admin/.ssh/id_ed25519 ((nil)) debug3: send packet: type 5 debug3: receive packet: type 7 debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com> debug3: receive packet: type 6 debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug3: send packet: type 50 debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,password debug3: start over, passed a different list publickey,password debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering public key: RSA SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaa /home/admin/.ssh/id_rsa debug3: send_pubkey_test debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 60 debug1: Server accepts key: pkalg rsa-sha2-512 blen 279 debug2: input_userauth_pk_ok: fp SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaa debug3: sign_and_send_pubkey: RSA SHA256:aaaaaaaaaaaaaaaaaaaaaaaaaaa debug3: send packet: type 50 debug3: receive packet: type 52 debug1: Enabling compression at level 6. debug1: Authentication succeeded (publickey). Authenticated to xx.xx.xxx.xxx ([xx.xx.xxx.xxx]:22). debug1: Local connections to LOCALHOST:13306 forwarded to remote address localhost:3306 debug3: channel_setup_fwd_listener_tcpip: type 2 wildcard 0 addr NULL debug3: sock_set_v6only: set socket 5 IPV6_V6ONLY debug1: Local forwarding listening on ::1 port 13306. debug2: fd 5 setting O_NONBLOCK debug3: fd 5 is O_NONBLOCK debug1: channel 0: new [port listener] debug1: Local forwarding listening on 127.0.0.1 port 13306. debug2: fd 6 setting O_NONBLOCK debug3: fd 6 is O_NONBLOCK debug1: channel 1: new [port listener] debug2: fd 3 setting TCP_NODELAY debug3: ssh_packet_set_tos: set IP_TOS 0x10 debug1: Requesting no-more-sessions@openssh.com debug3: send packet: type 80 debug1: Entering interactive session. debug1: pledge: network debug3: receive packet: type 80 debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0 debug3: receive packet: type 4 debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding debug3: receive packet: type 4 debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding debug1: Connection to port 13306 forwarding to localhost port 3306 requested. debug2: fd 7 setting TCP_NODELAY debug2: fd 7 setting O_NONBLOCK debug3: fd 7 is O_NONBLOCK debug1: channel 2: new [direct-tcpip] debug3: send packet: type 90 debug3: receive packet: type 91 debug2: channel 2: open confirm rwindow 2097152 rmax 32768 debug1: Connection to port 13306 forwarding to localhost port 3306 requested. debug2: fd 8 setting TCP_NODELAY debug2: fd 8 setting O_NONBLOCK debug3: fd 8 is O_NONBLOCK debug1: channel 3: new [direct-tcpip] debug3: send packet: type 90 debug3: receive packet: type 91 debug2: channel 3: open confirm rwindow 2097152 rmax 32768 debug3: receive packet: type 96 debug2: channel 3: rcvd eof debug2: channel 3: output open -> drain debug2: channel 3: obuf empty debug2: channel 3: close_write debug2: channel 3: output drain -> closed debug2: channel 3: read<=0 rfd 8 len 0 debug2: channel 3: read failed debug2: channel 3: close_read debug2: channel 3: input open -> drain debug2: channel 3: ibuf empty debug2: channel 3: send eof debug3: send packet: type 96 debug2: channel 3: input drain -> closed debug2: channel 3: send close debug3: send packet: type 97 debug3: channel 3: will not send data after close debug3: receive packet: type 97 debug2: channel 3: rcvd close debug3: channel 3: will not send data after close debug2: channel 3: is dead debug2: channel 3: garbage collecting debug1: channel 3: free: direct-tcpip: listening port 13306 for localhost port 3306, connect from 127.0.0.1 port 59650 to 127.0.0.1 port 13306, nchannels 4 debug3: channel 3: status: The following connections are open: #2 direct-tcpip: listening port 13306 for localhost port 3306, connect from 127.0.0.1 port 59644 to 127.0.0.1 port 13306 (t4 r0 i0/0 o0/0 fd 7/7 cc -1) #3 direct-tcpip: listening port 13306 for localhost port 3306, connect from 127.0.0.1 port 59650 to 127.0.0.1 port 13306 (t4 r1 i3/0 o3/0 fd 8/8 cc -1)
Locally I am using the following mysql-version:
admin@admin-VirtualBox:~$ mysql --version mysql Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using EditLine wrapper
When trying to connect via my local
mysql
-client it works fine:admin@admin-VirtualBox:~$ mysql --host=127.0.0.1 --port=13306 mysql -u root -p Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 136 Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +-----------------------------+ | Database | +-----------------------------+ | information_schema | | mysql | | performance_schema | | phpmyadmin | | sys | | test_db | +-----------------------------+ 7 rows in set (0.03 sec) mysql>
Also when using
dbeaver 7.3.5
works out fine:However, when trying to connect via the following php script I get an error in the log of my mysql-db
/etc/mysql/mysql.conf.d
I am using locally
PHP 7.4.1
and on the remote hostPHP 7.4.3
.<?php $mysqli = new mysqli("127.0.0.1", "root", "myPassword", "test_db", 13306); /* check connection */ if ($mysqli->connect_errno) { mysqli_debug("/home/marcus/Desktop/client.trace"); printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } /* check if server is alive */ if ($mysqli->ping()) { mysqli_debug("/home/marcus/Desktop/client.trace"); printf ("Our connection is ok!\n"); } else { printf ("Error: %s\n", $mysqli->error); } /* close connection */ $mysqli->close(); ?>
The error that I get remotely is:
2021-03-08T05:26:49.885317Z 132 [Note] [MY-010914] [Server] Got timeout reading communication packets
I also tried changing
$mysqli = new mysqli("localhost", "root", "myPassword", "test_db", 13306);
but this does not work as it seems to me thatmysqli
confuses this with mylocalhost
on my local machine. I only get the above error when using127.0.0.1
.Any suggestions what I am doing wrong? Why can I connect via my local
mysql client
and also withdbeaver
, BUT not via php?Is there a way to see how
mysqli()
builds the connection?I really appreciate your replies!
-
Can I type the less code to connect the database?
Situation: I need to select, insert and update data many times using SQL in a lot of pages.
Expected: Do not need to type a lot of connecting server information(see the code) many times such as mysql:host=$servername;dbname=$dbname", $username, $password in a lot of pages.
How Can I set it?
database.php
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "colands"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
body.php
require_once("dataBase.php"); $allthree = $conn->prepare("SELECT * FROM battleCalculator WHERE battleCalculator_battleField_id = $battleCalculator_battleField_id"); $allthree->execute(); } catch(PDOException $e){ { echo "Error: " . $e->getMessage(); } $conn = null; } ?>
-
BodyParser is deprecated
As the image shown, BodyPaser now is deprecated, how to correct the bodyPaser syntax or statement to remove the line-through?
-
How can I split string in Elasticsearch
I'm using nodejs as the client side for Elasticsearch, and got the following settings for the query. I want to split the text while users input text like "aa123 bb234" into "aa123 bb" "234". Only split the pattern like "bb234"(maybe b-z, except a ). How can I do that in elasticsearch settings?
settings: { analysis: { analyzer: { default: { type: 'custom', tokenizer: 'standard', filter: [ 'lowercase', 'my_shingle' ] } }, filter: { my_shingle: { type: "shingle", token_separator: "" } } } }
-
AWS sdk response structure issue
I am trying to collect savings plan utilization report using was aws-sdk from a NodeJs application. The API response values does not match with the cost explorer utilization report in the AWS Console.
Thanks in advance...
-
"Circular dependency detected" warning - Angular
This is the warning I get in the web browser. I would like to know the reason and how to fix it.
client:135 Circular dependency detected: src\app\employee\employee.component.ts -> src\app\shared\service\employee.service.ts -> src\app\employee\employee.component.ts
Here is my employee.component.ts file.
import {Component, OnInit} from '@angular/core'; import {EmployeeService} from '../shared/service/employee.service'; import {Employee} from '../shared/model/employee/employee.model'; @Component({ selector: 'app-employee', templateUrl: './employee.component.html', styleUrls: ['./employee.component.scss'] }) export class EmployeeComponent implements OnInit { activeEmployee: Employee; constructor(private employeeService: EmployeeService) { this.activeEmployee = this.employeeService.getActiveEmployee(); } ngOnInit(): void { } closeDialog(): void { // this.employeeService.dialogRef.close(); this.employeeService.closeDialogBox(); } }
Here is my employee.service.ts file.
import {Injectable} from '@angular/core'; import {Employee} from '../model/employee/employee.model'; import {MatDialog, MatDialogConfig, MatDialogRef} from '@angular/material/dialog'; import {EmployeeComponent} from '../../employee/employee.component'; import {Position} from '../model/employee/position.enum'; import {Status} from '../model/employee/status.enum'; import {Gender} from '../model/gender.enum'; const employeeSample = new Employee(2, 'John Doe', '22, Sample Road, Sample 03', new Date(Date.parse('01/01/1995')), 'XXXXXXXXX', '94-XXXXXXXX', 'john@temporary-mail.net', Gender.MALE, Position.INTERN, Status.ACTIVE, null // password ); @Injectable({ providedIn: 'root' }) export class EmployeeService { activeEmployee = employeeSample; dialogConfig: MatDialogConfig = new MatDialogConfig(); dialogRef!: MatDialogRef<any>; constructor(public dialog: MatDialog ) { this.dialogConfig = { width: '60%', height: '100%', disableClose: true }; } openDialogBox(): void { this.dialogRef = this.dialog.open(EmployeeComponent, this.dialogConfig); } closeDialogBox(): void{ this.dialogRef.close(); } getActiveEmployee(): Employee{ return this.activeEmployee; } }
-
How to extend a 3rd party directive and add custom logic in Angular 11?
I am new to Angular and Typescript and I wish to override the uploadImage function from ngx-summernote directive. I tried to extend the class, but I get error
'Class 'CustomNgxSummernoteDirective' incorrectly extends base class 'NgxSummernoteDirective'.Types have separate declarations of a private property 'uploadImage''.
Here is my extended directive code.
@Directive({ // tslint:disable-next-line:directive-selector selector: '[ngxSummernote]', providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CustomNgxSummernoteDirective), multi: true, }, ], }) export class CustomNgxSummernoteDirective extends NgxSummernoteDirective { private async uploadImage(files) { if (this._options.uploadImagePath) { this.imageUpload.emit({ uploading: true }); const requests = []; for (const file of files) { const data = new FormData(); data.append('image', file); const obs = this.http .post(this._options.uploadImagePath, data) .pipe( map( (response: { path: string }) => response && typeof response.path === 'string' && response.path ) ); requests.push(obs); } this.uploadSub = combineLatest(requests).subscribe( (remotePaths: string[]) => { for (const remotePath of remotePaths) { this._$element.summernote('insertImage', remotePath); } this.imageUpload.emit({ uploading: false }); }, (err) => this.insertFromDataURL(files) ); } else { this.insertFromDataURL(files); } } }
Please let me know if this is feasible to do, if so what change I have to do in derived class. Thanks in advance.
-
Too complicated Typescript question. Dynamic object references
So, I have a query that either returns the full object OR a reference to a path within the object. So, I have a base type for the object, but if you pass in this "path" I don't know how to apply the type...ala.
as an example:
type Product { id: number, name: string, size: EnumSizes color: Array<string>, someNestedKey: { id: number, count: number } }
some queryGetter:
const product: Product = getProductQueryCache(); // empty returns the full object const someValue: Product['name']???? = getQueyCache('name'); // returns just the name
but I think more, wouldn't I "type" it in the query? How would I do that?
function getProductQueryCache(value: string | null) { const product = getCache('product'); // returns everything.. if (!value) return product return get(product, value, null); // HOW TO TYPE THIS or even should? }
-
typeorm performance issue with postgres
i have a strange issue with typeorm and postgresql. below is a simple part of code in nest.js
@Get() async getHello(): Promise<any> { const keywords = 'wxample'; const now1: any = new Date(); await this.typeormConnection.query(` select admins.first_name from sessions JOIN admins ON sessions.admin_id = admins."id" LEFT JOIN companies ON companies."id" = admins.company_id WHERE admin_sessions.token = '${keywords}' `); const now2: any = new Date(); await this.pgConnection.query(` select admins.first_name from sessions JOIN admins ON sessions.admin_id = admins."id" LEFT JOIN companies ON companies."id" = admins.company_id WHERE admin_sessions.token = '${keywords}' `); console.log(`typeorm => ${now2 - now1}ms`); console.log(`pg => ${(new Date() as any) - now2}ms`); return 'ok'; }
if i connect it to Azure PostgreSQL the average result time would be:
typeorm => 1300ms
pg => 30msbut if i connect this code to AWS the result would be:
typeorm => 100ms
pg => 30msi 'm wondering why tge pure pg module is so fast on Azure but typeorm take time while typeorm is ok in AWS with same databased setup?
-
TypeORM: get all records that are in array
I have 2 arrays of ID's like this
availableTopics:['abc38475','abc74637','abc994006'], masteredLessons: ['abc88849', 'abc0000383']
and I want to create a query with typeORM to extract all records that have the relation of availableTopics and exclude all records that have the relation of masteredLessons but my query keeps crashing:
UnhandledPromiseRejectionWarning: QueryFailedError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
My code
const all = await connection .createQueryBuilder(Questions, 'questions') .addSelect('topics.id', 'topics_id') .addSelect('topics.UID', 'topics_UID') .addSelect('topics.name', 'topics_name') .addSelect('topics.chips', 'topics_chips') .addSelect('topics.tickets', 'topics_tickets') .addSelect('topics.masteredLevel', 'topics_masteredLevel') .addSelect('lessons.UID', 'lessons_UID') .addSelect('lessons.name', 'lessons_name') .addSelect('lessons.rule', 'lessons_rule') .addSelect('lessons.description', 'lessons_description') .innerJoin(Lessons, 'lessons', 'questions.lessonUID = lessons.UID') .innerJoin(Topics, 'topics', 'lessons.topicUID = topics.UID') .where('topics.UID IN (:...availableTopics)') .andWhere('lessons.UID NOT IN (:...masteredLessons)') .setParameters({availableTopics: user.path.availableTopics}) .setParameters({masteredLessons: user.path.masteredLessons}) .getRawMany()
-
How to use typeorm find and update multi datas
For example
@Entity("user") export class UserEntity extends BaseEntity { @Column() corpName: string; }
now I want to replace all datas like "corpName:google", "corpName:microsorft" with "corpName:Google", "corpName:Microsorft". Find and Update.