小编Iva*_*ita的帖子

PostgreSQL ADD COLUMN DEFAULT NULL锁定和性能

我的PostgreSQL 9.6数据库中有一个表,有300万行.该表已经有一个空位图(它有另外两个DEFAULT NULL字段).我想在这个表中添加一个新的布尔可空列.我坚持这两个陈述之间的区别:

ALTER TABLE my_table ADD COLUMN my_column BOOLEAN;
ALTER TABLE my_table ADD COLUMN my_column BOOLEAN DEFAULT NULL;
Run Code Online (Sandbox Code Playgroud)

我认为这些陈述没有区别,但是:

  1. 我在文档中找不到任何证据.文档告诉我们为DEFAULT新列提供值会使PostgreSQL重写所有元组,但我不认为这种情况是正确的,因为默认值是NULL.
  2. 我对这个表的副本进行了一些测试,第一个语句(没有DEFAULT NULL)比第二个语句花了更多的时间.我不明白为什么.

我的问题是:

  1. PostgreSQL会对ACCESS EXCLUSIVE这两个语句使用相同的锁类型()吗?
  2. PostgreSQL会重写所有元组NULL,以便在我使用的情况下为每个元组增加价值DEFAULT NULL吗?
  3. 这两个陈述之间有什么区别吗?

postgresql

13
推荐指数
2
解决办法
6062
查看次数

在Angular2中使用父组件的模板

我想在Angular中使用组件的继承继承父模板.

介绍

我有一些基本组件(让我们称之为ParentComponent)和这个组件的几个孩子(Child1ComponentChild2Component).我想在其中放置默认行为ParentComponent,然后在子组件中设置/扩展此行为.ParentComponent模板已包含所有需要的东西,所以我希望子组件默认使用此模板.


实现的第一个变体(不起作用Error: No template specified for component Child1Component):

@Component({
    selector: 'app-parent',
    templateUrl: './app-parent.component.html',
    styleUrls: ['./app-parent.component.scss']
})
export class ParentComponent {
}

@Component({
    selector: 'app-child1'
})
export class Child1Component extends ParentComponent {
}


@Component({
    selector: 'app-child2'
})
export class Child2Component extends ParentComponent {
}
Run Code Online (Sandbox Code Playgroud)

我发现我可以设置templateUrlstyleUrls孩子父母的模板,但如果只会工作,ViewEncapsulation孩子被设置为None.

第二个变种(它有效,但我不喜欢它):

@Component({
    selector: 'app-parent',
    templateUrl: './app-parent.component.html',
    styleUrls: ['./app-parent.component.scss']
})
export class ParentComponent …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

Sails.js + Waterline:通过关联多对多

我是Sails.js(v0.10.5)和Waterline ORM的新手.我在数据库中有3个表:users(id,name),roles(id,alias)和join table users_roles(user_id,role_id).重要的是不要更改数据库中的表名和字段名.我希望Policy实体成为User和Role之间的连接实体.这是一些映射代码:

//User.js
module.exports = {
    tableName: 'users',
    autoCreatedAt: false,
    autoUpdatedAt: false,
    attributes: {
        id: {
            type: 'integer',
            required: true
        },
        name: {
            type: 'string'
        },
        roles: {
            collection: 'role',
            via: 'users',
            through: 'policy'
        },
    }
}

//Role.js
module.exports = {
    tableName: "roles",
    autoCreatedAt: false,
    autoUpdatedAt: false,
    attributes: {
        id: {
            type: 'integer',
            required: true
        },
        alias: {
            type: 'string',
            required: true
        },
        users: {
            collection: 'user',
            via: 'roles',
            through: 'policy'
        }
    }
}

//Policy.js
module.exports = { …
Run Code Online (Sandbox Code Playgroud)

orm many-to-many sails.js waterline

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

无法在 - MappingException中找到目标实体

我有Symfony项目,其中有2个实体 - Building和Building_type.它们与ManyToMany单向关联相关联.所以,当我尝试访问我的控制器时,我有这个错误:

The target-entity Farpost\StoreBundle\Entity\Building_type cannot be found in 'Farpost\StoreBundle\Entity\Building#building_types'.
Run Code Online (Sandbox Code Playgroud)

Farpost/StoreBundle /实体/ Building.php:

    namespace Farpost\StoreBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;

    /**
     * @ORM\Entity
     *
     */
    class Building
    {
       /**
        * @var integer
        *
        * @ORM\Column(name="id", type="integer")
        * @ORM\Id
        * @ORM\GeneratedValue(strategy="AUTO")
        */
       protected $id;

       /**
        * @var string
        *
        * @ORM\Column(name="alias", type="string", length=255)
        */
       protected $alias;

       /**
        * @var string
        *
        * @ORM\Column(name="number", type="string", length=255)
        */
       protected $number;

       /**
        * @ORM\ManyToMany(targetEntity="Building_type")
        * @ORM\JoinTable(name="buildings_types",
        * joinColumns={@ORM\JoinColumn(name="building_id", referencedColumnName="id")},
        * inverseJoinColumns={@ORM\JoinColumn(name="building_type_id", referencedColumnName="id")} …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

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