I need help (Problem inside code.)
var db = new SQL.Database(); //instead of creating a new Database , i want to access one.
db.run("CREATE TABLE todos (id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT);");```
I've got records that were the result of bad data where the Partition Key is null and I need to clean them up, but I've been unsuccessful so far.
Here's what I've tried:
var scriptResult = await _dbClient.ExecuteStoredProcedureAsync<dynamic>(
GetStoredProcLink("BulkDelete"),
new RequestOptions() { PartitionKey = new PartitionKey(""), EnableScriptLogging = true },
"select * from c where c.documentDbType = "SomeValue"");
I've also tried used Undefined.Value as the parameter to new PartitionKey().
I ripped the stored proc from here and haven't changed anything yet.
Note: This is a partitioned collection if it was not obvious (by /companyId)
I just hit this issue when migrating to new database level throughput provision. This is syntax that got me up and running again when my models did not contain the specified partition Key property:
new RequestOptions() {
PartitionKey = new PartitionKey(Undefined.Value)
}
Ref:
https://www.lytzen.name/2016/12/06/find-docs-with-no-partitionkey-in-azure.html
Null, Undefined, and empty string are all different values in Cosmos DB. You need something like: new RequestOptions { PartitionKey = new PartitionKey(null) }
I am new to dynamodb, I am able to delete an item based on key.
Below is the code snippet:
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("hash", new AttributeValue().withS("hashEncodedStringValue"));
DeleteItemRequest deleteItemRequest = new DeleteItemRequest().withTableName("HashTable").withKey(key);
I need to delete items less than 7 days old from my table. And my table has a field called 'created_at' in this format "2017-10-25 14:54:52.278"
If you want dynamodb to delete it automatically after 7 days you can create TTL field and update the timestamp, dynamodb will automatically delete it.
Reference:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html
CRUD Operations with Java:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html
Hope it helps.
I have a web application based on ASP Core 1 with PostgreSql data storage. And now i want to add auth functionality. I have created base example mvc project with authorization and it works fine with MsSql server. But what about PostgreSql?
At first i create database with same schema (sql was generated via dnx ef migrations script and code was updated with pg-style). Then i have configured EF with Postgres
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(Configuration["Data:DefaultConnection:ConnectionString"]));
When i try to register as new user, i get an error 42P01: relation \"AspNetUsers\" does not exist. I have already surrounded table name with doublequotes, but it does not helps. I have no access to default auth models and can't add name atribute to table name and name of fields.
So, my questions are:
What wrong with my sample project and why i can't get access to db?
More globally. What is the best way to organize authorization and authentication with ASP Core 1 + PostgreSql? I no needed in all ASP auth features, i just neede in roles, i want to have bigint-based id and i want to extend users model (table).
Note: I use EF7.
So the answer for my first question is in the wrong database schema. For someone interested in schema i get the full pg sql code, but my second question is still opened.
CREATE TABLE public."AspNetRoles" (
"Id" character varying(450) NOT NULL,
"ConcurrencyStamp" text,
"Name" character varying(256),
"NormalizedName" character varying(256),
CONSTRAINT pk_identityrole PRIMARY KEY ("Id")
);
CREATE TABLE public."AspNetUsers" (
"Id" character varying(450) NOT NULL,
"AccessFailedCount" integer NOT NULL,
"ConcurrencyStamp" text,
"Email" character varying(256),
"EmailConfirmed" boolean NOT NULL,
"LockoutEnabled" boolean NOT NULL,
"LockoutEnd" timestamp without time zone,
"NormalizedEmail" character varying(256),
"NormalizedUserName" character varying(256),
"PasswordHash" text,
"PhoneNumber" text,
"PhoneNumberConfirmed" boolean NOT NULL,
"SecurityStamp" text,
"TwoFactorEnabled" boolean NOT NULL,
"UserName" character varying(256),
CONSTRAINT pk_applicationuser PRIMARY KEY ("Id")
);
CREATE TABLE public."AspNetRoleClaims" (
"Id" serial NOT NULL,
"ClaimType" text,
"ClaimValue" text,
"RoleId" character varying(450),
CONSTRAINT pk_identityroleclaim PRIMARY KEY ("Id"),
CONSTRAINT fk_identityroleclaim_identityrole_roleid FOREIGN KEY ("RoleId")
REFERENCES public."AspNetRoles" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserClaims" (
"Id" serial NOT NULL,
"ClaimType" text,
"ClaimValue" text,
"UserId" character varying(450),
CONSTRAINT pk_identityuserclaim PRIMARY KEY ("Id"),
CONSTRAINT fk_identityuserclaim_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserLogins" (
"LoginProvider" character varying(450) NOT NULL,
"ProviderKey" character varying(450) NOT NULL,
"ProviderDisplayName" text,
"UserId" character varying(450),
CONSTRAINT pk_identityuserlogin PRIMARY KEY ("LoginProvider", "ProviderKey"),
CONSTRAINT fk_identityuserlogin_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE public."AspNetUserRoles" (
"UserId" character varying(450) NOT NULL,
"RoleId" character varying(450) NOT NULL,
CONSTRAINT pk_identityuserrole PRIMARY KEY ("UserId", "RoleId"),
CONSTRAINT fk_identityuserrole_applicationuser_userid FOREIGN KEY ("UserId")
REFERENCES public."AspNetUsers" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_identityuserrole_identityrole_roleid FOREIGN KEY ("RoleId")
REFERENCES public."AspNetRoles" ("Id") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
I transfer my database from SQL SERVER to postgreSQL, after transfer, I found this error. when I checked my database, the table was in lowercase. I changed all AspTables and columns to default name and solved my problem.
How to query range key programmatically in DynamoDB, I am using .Net AWSSDK ,I am able to query on Hash key with below code :
GetItemRequest request = new GetItemRequest
{
TableName = tableName
};
request.Key = new Dictionary<string,AttributeValue>();
request.Key.Add("ID",new AttributeValue { S = PKValue });
GetItemResponse response = client.GetItem(request);
Please suggest,
Thanks in advance.
There are two kinds of primary key in DynamoDB: Hash-only or Hash-Range.
In the above code I guess your table is Hash-only and you use the hash key to retrieve an element with hashkey equals to PKValue.
If your table is in H-R schema and you want to retrieve a specific element with a hashKey and rangeKey, you can reuse the above code and in addition, add the {"RangeKey", new AttributeValue } into your your request.KEY
On the other hand, query means a different thing in DynamoDB. Query will return you a list of rows sorted in some order.