小编asu*_*sus的帖子

github actions - 在 postgres 服务中运行 sql 脚本

我想在 github actions 的 postgres 服务中运行一个脚本,创建一个表并添加一个扩展。我怎样才能做到这一点?我需要制作 shell 脚本还是可以直接在 yaml 文件中执行?

SQL脚本

drop database mydb;
create database mydb;
\c mydb;
CREATE EXTENSION "pgcrypto";
Run Code Online (Sandbox Code Playgroud)

工作流程

name: API Integration Tests

on: 
    pull_request:
    push:
        branches:
            -master

env:
    DB_HOST: localhost
    DB_USERNAME: postgres
    DB_PASSWORD: rt

jobs:
    build:
        runs-on: ubuntu-latest

        strategy:
          matrix:
            node-version: [10.x, 12.x, 13.x]


    services:
        postgres:
          image: postgres:latest
          env:
            POSTGRES_DB: mydb        
            POSTGRES_PASSWORD: helloworl
            POSTGRES_USER: postgres
          ports:
            - 5433:5432
          # Set health checks to wait until postgres has started
          options: >-
            --health-cmd pg_isready
            --health-interval 10s
            --health-timeout …
Run Code Online (Sandbox Code Playgroud)

postgresql github-actions

8
推荐指数
1
解决办法
4476
查看次数

Redux - createSlice 内标准化的嵌套数据组织

我有一个从 API 返回的深层嵌套数据对象,如下所示的 JSON。

我正在使用 Redux 工具包createSlice创建一个切片trip

所以目前在 my 中createSlice,我想存储一系列旅行。

我还希望能够更新单次行程或部分行程

  • 例如,假设我想更新旅行项目的开始日期
  • 或者,假设我想更新旅行项目的成员姓名

我的问题和疑虑:

  • 我目前将所有这些实体返回到 createSlice 中,trip但我不确定一旦实体标准化,是否应该将它们分成单独的createSlices?如果是这样,这是如何完成的或者这是一种反模式?
  • 嵌套实体应该如何定义initialState
  • 我应该在我的中定义所有规范化实体吗initalStatetrip_item如果我这样做,当我想更新or时,我的减速器会是什么样子trip_item_member
  • 我的标准化数据看起来“正确”吗?我省略了使用mergeStrategyBetweentrips_items_memberstrip_members我知道我应该这样做,但还没有弄清楚它是如何工作的或者这里是否有必要?

笔记:

RTK 文档中有一个示例,其中显示createSlice与 3 个单独的实体一起使用,这些实体最初来自 1 个 API 调用。它看起来像 3 个独立的文件,但尚不清楚它们之间如何共享数据。

这就是我的旅行createSlice的样子

/**
 * Get trip by ID action
 */
export const getTripByID = createAsyncThunk(
  'trips/getTripByID',
  async ({ uid }) => { …
Run Code Online (Sandbox Code Playgroud)

redux normalizr redux-toolkit

5
推荐指数
1
解决办法
2455
查看次数

TypeScript - Jest 的 mockResolvedValueOnce 方法中实体上的“不可分配给永不类型”错误

我已经看到在原始类型中解决了这个错误,但我不确定在这个例子中我将如何解决它

const newUser: UserEntity = {
      user_id: 'f3bea6de-fb24-4441-b75b-d7642ca573d7',
      name: 'Test User',
    };

jest.spyOn(repo, 'create').mockResolvedValueOnce([newUser]); // error here on [newUser] - 'UserEntity' is not assignable to type 'never'
Run Code Online (Sandbox Code Playgroud)

用户实体.ts

@Entity('users')
export class UserEntity {
  @PrimaryGeneratedColumn('uuid') user_id: string;
  @Column('text') name: string;
}
Run Code Online (Sandbox Code Playgroud)

typescript jestjs nestjs

3
推荐指数
1
解决办法
2637
查看次数

Nestjs - QueryFailedError:uuid 类型的输入语法无效

我有这个方法,应该返回所有用户的所有帖子 基本上是这样Select * from posts

  /**
   * Find all posts 
   */
  async findAll(): Promise<Post[]> {
    try {
      return await await getConnection()
      .createQueryBuilder()
      .select("posts")
      .from(Post, "posts").getMany();
    } catch (error) {
      throw new Error(error)      
    }
  }
Run Code Online (Sandbox Code Playgroud)

调用此方法时,这是 TypeORM 的响应

QueryFailedError: invalid input syntax for type uuid: "findAll"
Run Code Online (Sandbox Code Playgroud)

查询输出

SELECT DISTINCT
   "distinctAlias"."Post_post_id" as "ids_Post_post_id" 
FROM
   (
      SELECT
         "Post"."post_id" AS "Post_post_id",
         "Post"."uid" AS "Post_uid",
         "Post"."title" AS "Post_title",
         "Post"."sub_title" AS "Post_sub_title",
         "Post"."content" AS "Post_content",
         "Post"."userUserId" AS "Post_userUserId",
         "Post__comments"."comment_id" AS "Post__comments_comment_id",
         "Post__comments"."content" AS "Post__comments_content",
         "Post__comments"."postPostId" …
Run Code Online (Sandbox Code Playgroud)

postgresql uuid typeorm nestjs

2
推荐指数
1
解决办法
1万
查看次数

Spring AWS - 找不到所需的bean

我正在尝试启动我的 Spring 服务器,但不断收到此错误:

Description:

Parameter 0 of constructor in com.rm.awsimageupload.filestore.FileStore required a bean of type 'com.amazonaws.services.s3.AmazonS3' that could not be found.


Action:

Consider defining a bean of type 'com.amazonaws.services.s3.AmazonS3' in your configuration.
Run Code Online (Sandbox Code Playgroud)

我努力了:

  1. 将键作为字符串直接粘贴到BasicAWSCredentials
  2. 将钥匙放入application.properties,然后使用@Value即可访问它们。通过这种方法,我得到这个错误:
Error creating bean with name 'amazonConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'local.AWS_ACCESS_KEY_ID' in value "${local.AWS_ACCESS_KEY_ID}"
Run Code Online (Sandbox Code Playgroud)

应用程序属性

AWS_ACCESS_KEY_ID=NOTAREALKEY
AWS_SECRET_ACCESS_KEY=NOTAREALSECRET
Run Code Online (Sandbox Code Playgroud)

文件存储.java


@Configuration
public class AmazonConfig {

    @Value("${application.AWS_ACCESS_KEY_ID}")
    private String AWS_ACCESS_KEY_ID;

    @Value("${application.AWS_SECRET_ACCESS_KEY}")
    private String AWS_SECRET_ACCESS_KEY; …
Run Code Online (Sandbox Code Playgroud)

java spring amazon-s3 maven spring-boot

2
推荐指数
1
解决办法
1万
查看次数

Formik handleChange - 使用钩子

在安装 Formik 之前,我的输入如下所示:

         const [search, setSearch] = useState('');
         ....

         <View style={styles.profileEditContainer__top}>
          <TextInput
            style={styles.profileEditContainer__form}
            autoCapitalize="none"
            placeholder="Enter what you want to create.."
            placeholderTextColor={Colors.formPlaceHolderDefault}
            name="search"
            type="search"
            value={search}
            onChangeText={(e) => setSearch(e)}
            autoCorrect={false}
            defaultValue={search}
          />
          <Button
            disabled={!search}
            title="Create"
            onPress={(e) => {
              createNewCar(e);
            }}
          />
        </View>
Run Code Online (Sandbox Code Playgroud)

在 中onChangeText,我会将输入的每个字符设置为名为 的状态道具search。我输入的每一个键都会调用一个 API 来从数据库中获取一些数据。

例如:

如果我h输入,数据库将返回 2 辆汽车honda, hyundai

我读到 Formik 可以简化 React 中的很多表单设置,所以我下载了它,但是,handleChangeFormik 的 prop 想要跟踪values.search

         <Formik
          initialValues={{
            search,
          }}
          onSubmit={(values) => {
            console.log('values', values);
          }}>
          {({ handleChange, …
Run Code Online (Sandbox Code Playgroud)

react-native formik

2
推荐指数
1
解决办法
3210
查看次数

Redux - immer 与 Normalizr

我过去曾使用过immer ,并且非常喜欢它。它使得使用 redux 变得轻而易举。我最近发现了normlizr,它看起来也很棒。

两者有什么区别?immer 是否提供与 Normalizr 相同的标准化解决方案?对于生产应用程序来说,这两者中哪个是更好的选择?或者它们应该一起使用吗?

redux normalizr immer.js

2
推荐指数
1
解决办法
1777
查看次数

Redux Toolkit - 将整个数组分配给 state

如何使用 RTK 将整个数组分配给我的 intialState 对象?

state = payloadstate = [...state, ...payload]不更新任何东西。

例子:

const slice = createSlice({
  name: 'usersLikedPosts',
  initialState: [],
  reducers: {
    getUsersLikedPosts: (state, { payload }) => {
      if (payload.length > 0) {
        state = payload
      }
    },
  },
})
Run Code Online (Sandbox Code Playgroud)

有效载荷如下所示:

[
  0: {
    uid: '1',
    title: 'testpost'
  }
]
Run Code Online (Sandbox Code Playgroud)

更新

这样做有效,但我不知道这是否是正确的方法。任何人都可以评论吗?

payload.forEach((item) => state.push(item))
Run Code Online (Sandbox Code Playgroud)

redux redux-toolkit

2
推荐指数
1
解决办法
1501
查看次数

ReactJS语义ui-当值属性存在时无法键入表格

我正在遵循ReactJS教程来设置登录表单。使用和导入了语义ui。电子邮件和密码将传递到value表单内的属性中。发生这种情况时,我无法在表单中输入任何内容。删除它后,我就可以输入信息了,但我认为它不会传递到任何地方。

似乎在其他任何地方都找不到此问题。有人遇到过这个问题吗?

import React from 'react';
import PropTypes from 'prop-types';
import { Form, Button } from 'semantic-ui-react';
import Validator from 'validator';
import InlineError from '../messages/InlineError';



class LoginForm extends React.Component {
    state = {
        data: {
            email: "",
            password: ""
        },
        loading: false,
        errors: {}
    };

    //... is called spread
    onChange = e => this.setState({
        data: {...this.state.data, [e.target.name]: e.target.value }
    });

    //() means function takes no params
    onSubmit = () => {
        const errors = this.validate(this.state.data);
        this.setState({errors}); //if there …
Run Code Online (Sandbox Code Playgroud)

forms reactjs semantic-ui

1
推荐指数
1
解决办法
1295
查看次数

Node.js,Express.js - 意外令牌{

我的应用程序每次到达此行时都会崩溃:

const {name, price} = req.query;
        ^
Run Code Online (Sandbox Code Playgroud)

似乎无法找到确切的答案..错误日志

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3
Run Code Online (Sandbox Code Playgroud)

背景:

app.get('/products/add' , (req, res) => {
  const {name, price} = req.query;

  const INSERT_PRODUCTS_QUERY = `INSERT INTO products (name, price) VALUES ('${ name }', ${ price })`;
  connection.query(INSERT_PRODUCTS_QUERY, (err,results) => {
      if(err)
      {
        return res.send(err);
      }
      else
      {
        return res.send('succesfully added product');
      }
  });
});
Run Code Online (Sandbox Code Playgroud)

node.js express unexpected-token

0
推荐指数
1
解决办法
503
查看次数