constraints

Constraints on interface members in typescript generics

微笑、不失礼 提交于 2019-12-01 21:12:37
I have a method, that should accepts any object, as long as all its fields are strings or numbers I made this, which works great with duck typing static interpolateParams( route: string, params: {[key: string] : string | number}) : string { const parts = route .split("/") .map(part => { const match = part.match(/:([a-zA-Z09]*)\??/); if (match) { if (!params[match[1]]) { console.error("route argument was not provided", route, match[1]); return part; } return params[match[1]]; } else { return part; } }) return "/" + parts.slice(1).join("/"); } and call interpolateParams("/api/:method/:value",

What happens when I drop a clustered primary key in SQL 2005

微笑、不失礼 提交于 2019-12-01 19:25:21
I've a PK constraint - a clustered index on two columns - which I am in the process of dropping. The command is still running after an hour. I would have thought that as I am just removing a constraint the operation would be nearly instantaneous. Can someone explain to me what is actually happening under the hood when I drop the PK? Clustered index is not "just a constraint", it's a storage method. When you drop it, your data are being reordered from clustered storage to heap storage Other indexes are being updated to refer to RID 's instead of PRIMARY KEY values. The clustered index is the

MySql primary key constraint with name

半世苍凉 提交于 2019-12-01 18:58:34
Data definition statement: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ) What is the value and purpose of CONSTRAINT pk_PersonID PRIMARY KEY (P_Id) ? as opposed to this PRIMARY KEY (P_Id) ? MySql docs do not really say much about this except for this . Marki555 It's the same as MySQL ignores the CONSTRAINT pk_PersonID part. You can check by creating the table and then dumping it or issuing SHOW CREATE TABLE Persons . I guess it supports this syntax only for

Linq To Sql - SQL Default Constraint Problem

Deadly 提交于 2019-12-01 18:24:19
I have a USER table in database. The table has a RegistrationDate column which has a default constraint as GETDATE(). When using LINQ, I don't provide any data for RegistrationDate column to make it default. But SQL Server raises error. I think LINQ tries to insert NULL into the column. How can I make LINQ not to try to insert in the column RegistrationDate, because it has default value? Set Auto Generated Value property to true in the designer. Or IsDbGenerated="true" in .dbml file. I am not 100% sure, but you could make the property read-only in the DBML designer. 来源: https://stackoverflow

Violation of Primary Key error on Identity column

纵然是瞬间 提交于 2019-12-01 17:17:37
This is maddening! Code in question has been running for over 5 years. Here's the scoop.... I am doing an INSERT...SELECT into a table with a primary key that is an identity column. I do not specify the key when I insert - SQL Server generates it as expected. I am doing the insert in a stored procedure that I call in a loop (for loop in SSIS, actually). The stored procedure will insert rows in batches (configurable). It might insert 1000 rows at a time or it might insert 50,000 - doesn't matter. It will work for a random number of calls (inserting thousands of rows) and then it will fail, out

How to add a positive integer constraint to a integer column in MySQL?

浪子不回头ぞ 提交于 2019-12-01 16:54:06
How can we add a constraint which enforces a column to have only positive values. Tried the following mysql statement but it doesn't work create table test ( test_column integer CONSTRAINT blah > 0); You would use the keyword unsigned to signify that the integer doesn't allow a "sign" (i.e. - it can only be positive): CREATE TABLE test ( test_column int(11) unsigned ); You can read more about the numeric data types (signed & unsigned) here . As far as an actual constraint to prevent the insertion-of negative values, MySQL has a CHECK clause that can be used in the CREATE TABLE statement,

Force generic interface implementation in C#

别说谁变了你拦得住时间么 提交于 2019-12-01 16:04:03
Is there anyway to force a constraints for a generic definition to implement a "generic interface" ... that is, I want the class to support passing an interface and a generic class constraining it so that the class implements the interface. For example if I say: MyGenericClass<IMyInterface, MyImplementation>.DoSomething(); That should be constrained so that MyImplementation implements IMyInterface As far as I know that can be achieved by public class Dynamic_Loader<T, S> where S: T Now, is there anyway to also force T to be an interface? Edit: The purpose of this was to have something like:

Unique constraint for permutations across multiple columns

戏子无情 提交于 2019-12-01 15:40:18
问题 Given the following three columns in a Postgres database: first, second, third; how can I create a constraint such that permutations are unique? E.g. If ('foo', 'bar', 'shiz') exist in the db, ('bar', 'shiz', 'foo') would be excluded as non-unique. 回答1: You could use hstore to create the unique index: CREATE UNIQUE INDEX hidx ON test USING BTREE (hstore(ARRAY[a,b,c], ARRAY[a,b,c])); Fiddle UPDATE Actually CREATE UNIQUE INDEX hidx ON test USING BTREE (hstore(ARRAY[a,b,c], ARRAY[null,null,null]

Force generic interface implementation in C#

余生长醉 提交于 2019-12-01 15:23:50
问题 Is there anyway to force a constraints for a generic definition to implement a "generic interface" ... that is, I want the class to support passing an interface and a generic class constraining it so that the class implements the interface. For example if I say: MyGenericClass<IMyInterface, MyImplementation>.DoSomething(); That should be constrained so that MyImplementation implements IMyInterface As far as I know that can be achieved by public class Dynamic_Loader<T, S> where S: T Now, is

How to specify types not allowed in a .NET Generics constraint?

╄→гoц情女王★ 提交于 2019-12-01 15:16:57
Is it possible to specify a constraint on a generic class that disallows certain types? I don't know if it is possible and if it is, I am not sure what the syntax would be. Something like: public class Blah<T> where : !string { } I can't seem to find any notation that would allow such a constraint. The closest you can get is a run-time constraint. Edit : Originally I put the run-time check in the constructor call. That's actually not optimal, as it incurs overhead on every instantiation; I believe it would be much more sensible to put the check in the static constructor, which will be invoked