请帮我写查询。
我有 2 个表:“项目”和“债务”
“债务”表有
id | project_id | currency_list | total
1 | 1 | 1 | 1000
2 | 1 | 2 | 500
3 | 2 | 1 | 1000
4 | 2 | 2 | 500
...
Run Code Online (Sandbox Code Playgroud)
我需要编写查询以从项目中获取 1000 行,并将所有“总计”与“currency_list”组相加
非常感谢 :)
我有两个不同的项目。Laravel 项目 A 和 Laravel 项目 B。我需要通过队列从项目 A 到项目 B 创建任务。我不想在项目 A 中为此创建工作。
目前我的认识是:
项目A
有状态但没有业务逻辑的工作:
<?php
namespace App\Jobs;
use ...;
/**
* Fake class!!!
*/
class MyJob extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public $queue = 'MyQueue';
/**
* Some state
*/
protected $_contentId;
public function __construct($contentId)
{
$this->_contentId = $contentId;
}
/**
* Excess. I dont need business logic in project A.
*/
public function handle()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我在项目 A 中将作业推入队列:
...
$this->dispatch(
new MyJob($this->_contentId) …Run Code Online (Sandbox Code Playgroud) 我已经创建了下一个 XML:
item = E('p') # <p/>
Run Code Online (Sandbox Code Playgroud)
现在我需要将下一个内容放入其中:
text = "some <bold>text</bold>"
# item.append(text)
# TypeError: Argument 'element' has incorrect type (expected lxml.etree._Element, got str)
# item.append(fromstring(text))
# lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1
Run Code Online (Sandbox Code Playgroud)
结果我需要下一个 XML 节点:
<p>some <bold>text</bold></p>
Run Code Online (Sandbox Code Playgroud)
如何正确地做到这一点?
我的Dockerfile:
FROM mm_php:7.1
ADD ./docker/test/source/entrypoint.sh /work/entrypoint.sh
ADD ./docker/wait-for-it.sh /work/wait-for-it.sh
RUN chmod 755 /work/entrypoint.sh \
&& chmod 755 /work/wait-for-it.sh
ENTRYPOINT ["/work/entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)
entrypoint.sh:
#!/bin/bash -e
/work/wait-for-it.sh db:5432 -- echo "PostgreSQL started"
./vendor/bin/parallel-phpunit --pu-cmd="./vendor/bin/phpunit -c phpunit-docker.xml" tests
Run Code Online (Sandbox Code Playgroud)
泊坞窗,compose.yml:
version: '2'
services:
test:
build:
context: .
args:
ssh_prv_key: ${ssh_prv_key}
application_env: ${application_env}
dockerfile: docker/test/source/Dockerfile
links:
- db
db:
build:
context: .
dockerfile: docker/test/postgres/Dockerfile
environment:
PGDATA: /tmp
Run Code Online (Sandbox Code Playgroud)
.gitlab-ci.yml:
image: docker:latest
services:
- name: docker:dind
command: ["--insecure-registry=my.domain:5000 --registry-mirror=http://my.domain"]
before_script:
- apk add --no-cache py-pip
- pip install …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Symfony 创建新的迁移:
$ php app/console doctrine:migrations:generate
Generated new migration class to "/path/to/project/app/DoctrineMigrations/Version20100621140655.php"
Run Code Online (Sandbox Code Playgroud)
但我想用 nameVersion20100621140655_MyName.php而不是Version20100621140655.php. 我怎样才能做到这一点?
编辑
我有my_table带有jsonb列的表sentiments。我需要从此列中删除所有键“10216”和“10191”。
我尝试在 Laravel 中做下一步:
DB::table('my_table')
->whereRaw("sentiments ?| ARRAY['10216', '10191']")
->update([
'sentiments' => DB::raw("sentiments - '10216' - '10191'")
]);
Run Code Online (Sandbox Code Playgroud)
但我有下一个错误:
[Illuminate\Database\QueryException]
SQLSTATE[42601]: Syntax error: 7 ??????: ?????? ?????????? (????????? ?????????: "$1")
LINE 1: ...= sentiments - '10216' - '10191' where sentiments $1| ARRAY[...
^ (SQL: update "my_table"
set "sentiments" = sentiments - '10216' - '10191'
where sentiments ?| ARRAY['10216', '10191'])
Run Code Online (Sandbox Code Playgroud)
因为正如我所看到的“?” 看起来像参数。如何逃避这个符号?
更新
我也试着写两个问题sentiments ??| ARRAY::
[Illuminate\Database\QueryException]
SQLSTATE[42883]: Undefined function: 7 ??????: ???????? …Run Code Online (Sandbox Code Playgroud) laravel ×3
php ×3
docker ×1
gitlab ×1
gitlab-ci ×1
join ×1
laravel-5.2 ×1
laravel-5.3 ×1
lxml ×1
pdo ×1
postgresql ×1
python ×1
python-3.x ×1
sum ×1
symfony ×1