I'm currently using PlantUML to design my database's ERD. All's well, the diagram is complete, but I'm trying to add a background color to my entities, to dintinguish them in their respective schemas.
I'm thinking of a backgroung color for the entities, or maybe a colored rectangle that holds the entities within it.
I tried using skinparam with the name of the entity, with its alias...
skinparam entity {
backgroundColor<<usr>> DarkOrchid
}
skinparam entity {
backgroundColor<<User>> DarkOrchid
}
None of these work... Can anybody help?
Thanks
=========
EDIT
As requested, a small example:
'==========='
'auth schema'
entity "User" as usr {
*id : number <<PK>>
--
password: varchar
salt: varchar
role: number <<FK>>
last_login_at : datetime
is_active : boolean
}
entity "User Role" as url {
*id : number <<PK>>
--
name: varchar
clearance_lvl: text
is_active : boolean
}
'====================='
'personnel data schema'
entity "Professor" as prof {
*id : number <<PK>>
--
name: varchar
office: integer
user_id: number <<FK>>
wage: number
last_login_at : datetime
is_active : boolean
}
entity "Student" as stu {
*id : number <<PK>>
--
name: varchar
semester: text
user_id: number <<FK>>
specialization: text
is_active : boolean
}
usr ||--o{ url
prof ||--|| usr
stu ||--|| usr
This generates the following diagram:
And I want to see something like this:
Or at least somthing like this:
The entity object uses the skinparams of class ! So, you would have to say skinparam class instead of skinparam entity to change the background color of your entities.
To apply a certain background color to a selection of entities, you would have to add a stereotype to them so that they can be identified by the skinparam class command. For example, you could add <<personnel>> to the Professor and Student entities and BackgroundColor<<personnel>> to skinparam class.
This should fulfill the requirements of your first example:
skinparam class {
BackgroundColor<<personnel>> #A9DCDF
}
'==========='
'auth schema'
entity "User" as usr {
*id : number <<PK>>
--
password: varchar
salt: varchar
role: number <<FK>>
last_login_at : datetime
is_active : boolean
}
entity "User Role" as url {
*id : number <<PK>>
--
name: varchar
clearance_lvl: text
is_active : boolean
}
'====================='
'personnel data schema'
entity "Professor" as prof <<personnel>> {
*id : number <<PK>>
--
name: varchar
office: integer
user_id: number <<FK>>
wage: number
last_login_at : datetime
is_active : boolean
}
entity "Student" as stu <<personnel>> {
*id : number <<PK>>
--
name: varchar
semester: text
user_id: number <<FK>>
specialization: text
is_active : boolean
}
usr ||--o{ url
prof ||--|| usr
stu ||--|| usr
To implement your second example, you could wrap your entities into packages and apply a different background directly as part of the package statement.
'==========='
'auth schema'
package "auth schema" #B4A7E5 {
entity "User" as usr {
}
entity "User Role" as url {
}
}
'====================='
'personnel data schema'
package "personnel data schema" #A9DCDF {
entity "Professor" as prof <<person>> {
}
entity "Student" as stu <<person>> {
}
usr ||--o{ url
prof ||--|| usr
stu ||--|| usr
Related
I have two entity models (Match and Partner), one of which contains two references to the other (partner1 and partner2).
#Entity("partner")
export class PartnerEntity {
#PrimaryGeneratedColumn("uuid")
id: string
#Column()
text: string
}
#Entity("match")
export class MatchEntity {
#PrimaryGeneratedColumn("uuid")
id: string
#ManyToOne(() => PartnerEntity, partner => partner.id)
#JoinColumn()
partner1?: PartnerEntity
#ManyToOne(() => PartnerEntity, partner => partner.id)
#JoinColumn()
partner2?: PartnerEntity
}
I am trying to persist a MatchEntity object using the Repository class from TypeORM like this:
this.matchRepository.save({
partner1: { text: "AAA" },
partner2: { text: "BBB" }
})
However, the same value is being saved for partner1 and partner2. I can confirm both that the object is correct and that the row stored in the database has the same value for the two foreign keys. The following object is returned:
{
id: "c58f3ea7-5002-463d-92e7-94d0c2992784",
partner1: { id: "10978976-d120-4e48-a490-eba62e7c06e5", text: "AAA" },
partner2: { id: "10978976-d120-4e48-a490-eba62e7c06e5", text: "AAA" }
}
What is wrong with my code? Is there a way to make this work?
Options that were considered but that I'd rather avoid for this use case:
Implementing a ManyToMany relationship instead (convert the two fields into an array with two positions)
Inserting new rows with explicit SQL queries using Repository.createQueryBuilder()
Below is my prisma schema
model Allegations {
allegation_id String #id #db.VarChar(200)
faculty String? #db.VarChar(200)
department String? #db.VarChar(200)
course String? #db.VarChar(200)
instructor String? #db.VarChar(200)
instructorEmail String? #db.VarChar(200)
instructorPh String? #db.VarChar(200)
details String? #db.VarChar(200)
allegationDate DateTime? #db.DateTime(0)
violationDate DateTime? #db.DateTime(0)
Students Students[]
}
model Students {
id String #id #db.VarChar(200)
student_name String? #db.VarChar(200)
banner String? #db.VarChar(200)
allegation_id String? #db.VarChar(200)
Allegations Allegations? #relation(fields: [allegation_id], references: [allegation_id], onDelete: Restrict, onUpdate: Restrict, map: "Students_ibfk_1")
##index([allegation_id], map: "allegation_id")
}
So far I got his but getting errors. I also tried inserting seperately into allegations and students, but the insert in students doesn't go through.
prisma.allegations.create({
data: {
allegation_id:key,
faculty: Faculty,
department: Department,
course: Course,
instructor: Instructor,
instructorPh: PhoneNumber,
instructorEmail: InstructorEmail,
details: Details,
allegationDate: date,
violationDate: OffenceDate,
Students:{
create:{
student_name: 'kn',
banner: '555555'
},
}
}
});
Modifying your code snippet slightly, I was able to correctly insert a record into the database. Also, you have to specify the student ID because you do not have the #default attribute on the Student schema. Find the modified code below
const allegation = await prisma.allegations.create({
data: {
allegation_id:"1",
faculty: "Science",
department: "Biochemistry",
course: "BCH101",
instructor: "John Doe",
instructorPh: "+231345678",
instructorEmail: "johndoe#test.com",
details: "some details",
allegationDate: new Date('2022','07', '31'),
violationDate: new Date('2022','08', '01'),
Students:{
create:{
id: 'std1',
student_name: 'Test Student',
banner: '555555'
},
}
}
})
we have 3 tables:
human
-----
PK: id
characteristic
--------------
PK: id
name
human_characteristic
--------------------
PK: id
FK: human_id
FK: characteristic_id
value
and I am trying to build a view table with:
human_characteristic_view
-------------------------
human_id
human_characteristics_with_name
so with TypeOrm with view table,
#ViewEntity({ ...? })
export class HumanCharacteristicView {
#ViewColumn()
human_id: string;
#Column({ type: 'jsonb', array: false, default: () => "'[]'", nullable: false })
human_characteristics: Array<HumanCharacteristicWithName>
}
HumanCharacteristicWithName is simply an interface extending HumanCharacteristic, but adding name field from Characteristic entity..
What should go into "...?" area?
I tried:
creating query builder,
select human_characteristic.human_id as human_id
from human_characteristic
left join (...?) << struggling with jsonb here
groupBy human_id
Any help will be appreciated, thank you!
I'm trying to query over the table products to find, Certain products that have "at least" Category "Food", "Cold".
I hope someone can give me a hand to be able to query for 2 or more Categories
I'm able to make it dynamic but I'm struggling hard on the queryBuilder
#Entity()
export class Product{
#Property()
#ManyToMany(() => Category, category=> category.products)
#JoinTable({
name: "product_category",
joinColumn: {
name: "product",
referencedColumnName: "Id"
},
inverseJoinColumn: {
name: "category",
referencedColumnName: "Id"
}
})
categories: Category[];
}
#Entity()
export class Category {
#Property()
#PrimaryGeneratedColumn("uuid")
Id: string;
#Column()
#Property()
name: string;
#Property()
#ManyToMany(() => LibraryItems, libraryItem => libraryItem.categories)
products: Product[];
}
I have tried using this:
query.where("categories.name IN(:...name1) AND categories.name IN(:...name2)", { name1: "Food", name2: "Cold" })
As we discuss. this is an example of the query will be:
...select(["count(categories.name) as count","o.*"])
// count(categories.name) here to get total of categories
.where('categories.name in (:...categories)',{categories})
// filter by user ids we need
.groupBy('product.id')
.having("count = :count", {count:categories.length})
// here we check if the products has the categories we want
.getRawMany();
PS: as you mentioned in the comment this question will return the rows with at least the categories wanted
FOR GLOBAL EXAMPLE WITH MYSQL QUERY using W3SCHOOL DATABASE Editor
SELECT o.*,count(o.OrderID) as total FROM OrderDetails as o join Products as p on o.ProductId = p.ProductID where o.ProductID in (11) group by o.OrderID having total = 3;
I am building an API where I have several fields that are optional in my get request. So I want MongoDB to match all values for those optional fields if the user does not specify it. I have come up with this solution:
db.collection(expenses_collection).find(username: username, category: {$regex:"/" + category + "/"}, payment_type: {$regex:"/" + payment_type + "/"}})
Where if category and payment_type are not specified by the user I set them to ".*":
const {category=".*", payment_type=".*"} = req.query;
However, mongodb is still not matching any data. Any help is appreciated. Thanks a lot.
The issue is with your regex string. To match any string value, you have to use this pattern (this matches any string): (.*?)
Consider input documents:
{ _id: 1, name: "John", category: "cat 1", payment_type: "cash" },
{ _id: 2, name: "Jane", category: "cat 2", payment_type: "credit card" }
Usage to match any category field value:
let categoryStr = /(.*?)/
db.exp.find( { category: categoryStr } )
The query returns all documents.
So, in your application for the category value not specified the code can be like this:
if (category is empty or null) { // category not specified by user
categoryStr = /(.*?)/
}
Similarly, for the payment_type field also.
Then query would be:
db.exp.find( {
username: usernameStr,
category: categoryStr,
payment_type: paymentStr
} )
NOTE: The code tests fine with MongoDB NodeJS driver APIs.
Isn't this what exists is made for?
{category: { $exists: true }, payment_type: { $exists: true }}