在Cloud Spanner文档的Node.js示例中,我学习了如何从我的Cloud Spanner数据库中查询,读取,插入和更新记录。 但我不知道如何删除'记录。
由于插入和更新方法只是“tablename.insert(...)'和' tablename.update(...)',我试过了tablename.delete(...)'但它删除了表本身。我想删除记录......似乎DML语句在查询中不起作用。
如何使用Google的Cloud Spanner从数据库中删除记录?
答案 0 :(得分:2)
您想要$(".tripType").click (function () {
$(".border-highlight").removeClass('border-highlight');
$(this).addClass('border-highlight');
chosenID = $(this).attr("id");
$("#tripTypeField" + chosenID).val(chosenID);
});
。
deleteRows
链接文档:Google CloudNode⇒CloudSpanner⇒表⇒deleteRows
答案 1 :(得分:1)
正如@Dan McGrath正确指出的那样,delete()实际上删除了表
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use App\Entity\Products;
use App\Entity\Settings;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Twig\Environment;
class CheckwebsitesCommand extends Command
{
private $entityManager;
private $mailer;
private $twig;
public function __construct(
EntityManagerInterface $entityManager,
\Swift_Mailer $mailer,
Environment $twig
)
{
parent::__construct();
$this->entityManager = $entityManager;
$this->mailer = $mailer;
$this->twig = $twig;
}
protected static $defaultName = 'checkwebsites';
protected function configure()
{
$this
->setName('app:checkwebsites')
->setDescription('Add a short description for your command')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$websites = $this->entityManager
->getRepository(Products::class)
->findBy([
'type' => 1,
]);
$settings = $this->entityManager
->getRepository(Settings::class)
->findOneBy([
'id' => 1,
]);
$json = $settings->getJson();
foreach($json as $prop) {
foreach($prop as $key => $value) {
$$key = $value;
}
}
//funkcja sprawdzająca czy strona działa
function url_test( $url ) {
$timeout = 10;
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
$http_respond = curl_exec($ch);
$http_respond = trim( strip_tags( $http_respond ) );
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
if ( ( $http_code == "200" ) || ( $http_code == "302" ) ) {
return true;
} else {
// return $http_code;, possible too
return false;
}
curl_close( $ch );
}
foreach($websites as $website) {
$www = $website->getJson();
$url = $www['website']['www'];
$online = url_test($url);
if(!$online) {
$message = (new \Swift_Message('Nie działa strona '.$www['website']['www'].' !'))
->setFrom(''.$emailform.'')
->setTo(''.$emailform.'')
->setBody(
$this->twig->render(
'emails/websitenoworking.html.twig',
array(
'www' => $url,
'firma' => $www,
)
),
'text/html'
);
$mailer->send($message);
}
}
$io->success('Sprawdzono wszystkie strony.');
}
}
要删除行(记录),请使用deleteRows()
table.delete()
.then(function(data) {
const operation = data[0];
return operation.promise();
})
.then(function() {
// Table deleted successfully.
});
从https://cloud.google.com/nodejs/docs/reference/spanner/2.0.x/Table
中了解更多信息