關系型數據庫的核心單元是
Nucleoid is an open source (Apache 2.0), a runtime environment that provides logical integrity in declarative programming, and at the same time, it stores declarative statements so that it doesn’t require external database, in short it can be used as database.
Nucleoid是一個開放源代碼(Apache 2.0),它是一個運行時環境,可在聲明式編程中提供邏輯完整性,同時,它存儲聲明性語句,因此不需要外部數據庫,總之可以用作數據庫。
數據結構 (Data Structure)
Data structures are defined in declarative syntax. Let’s say name
is a variable, and by program requirements, name
must be:
數據結構以聲明性語法定義。 假設name
是一個變量,并且根據程序要求, name
必須為:
- less than 10 characters 少于10個字符
- first character is upper case 第一個字符為大寫
- contains no underscore character 不含下劃線字符
so, this can be 3 separate declarations:
因此,這可以是3個單獨的聲明:
> if( name.length > 10 ) {
throw "INVALID_SIZE"
}> if( ! /[A-Z]/.test( name.charAt(0) )) {
throw "INVALID_FIRST_CHARACTER"
}> if( name.indexOf("_") > -1 ) {
throw "INVALID_SPECIAL_CHARACTER"
}
人際關系 (Relationships)
Relationships of objects are defined similar to database’s relationships, but it requires to define in declarative syntax.
對象的關系的定義與數據庫的關系類似,但是需要使用聲明性語法進行定義。
一對一 (One-to-One)
One-to-one’s defined as referring object’s property to another object instance.
一對一的定義是將對象的屬性引用到另一個對象實例。
> class Driver {}
> class Vehicle {}> driver1 = new Driver();
> vehicle1 = new Vehicle();
> driver1.vehicle = vehicle1;
Bidirectional relationships requires additional declaration in order to keep both side synced, so not recommended unless absolutely required, associative entity may be used as alternative.
雙向關系需要額外的聲明才能使雙方保持同步,因此除非絕對必要,否則不建議使用關聯實體作為替代。
Still all the declarations are applicable to the property:
所有聲明仍然適用于該屬性:
> Vehicle.type = "CAR"
> driver1.vehicle.type
"CAR"
一對多 (One-to-Many)
One-to-Many is defined in three ways:
一對多定義有以下三種方式:
列在身邊 (List as in One’s side)
It is a list created as property:
這是一個創建為屬性的列表:
> class Customer {}
> class Order {}> Customer.orders = [];> customer1 = new Customer();
> order1 = new Order();
> customer1.orders.push(order1);
像Manys一樣的財產 (Property as in Many’s side)
It is a property created, which refers to other instance:
這是一個創建的屬性,它引用其他實例:
> class Employee {}
> class Project {}> employee1 = new Employee()
> project1 = new Project();
> project1.employee = employee1;
Both of first 2 options are not bidirectional.
前兩個選項都不是雙向的。
關聯實體 (Associative Entity)
In this case, both objects will be registered in associative object:
在這種情況下,兩個對象都將被注冊到關聯對象中:
> class User {}
> class Company {}
> class Registration {}> if ( Registrations.filter( r => r.user == User ).length > 1 ) {
throw "USER_ALREADY_REGISTERED"
}> user1 = new User();
> company1 = new Company();> registration1 = new Registration();
> registration1.company = company1;
> registration1.user = user1;
Having a declaration of if ( Registrations.filter( r => r.user == User ).length > 1 ){ .. }
adds One-to-Many constraint. In this case, registering user1
to another company throws "USER_ALREADY_REGISTERED"
:
如果聲明為if ( Registrations.filter( r => r.user == User ).length > 1 ){ .. }
添加一對多約束。 在這種情況下,向另一家公司注冊user1
會引發"USER_ALREADY_REGISTERED"
:
> company2 = new Company();
> registration2 = new Registration();
> registration2.company = company2
> registration2.user = user1;
> "USER_ALREADY_REGISTERED"
多對多 (Many-to-Many)
Many-to-Many is relatively straightforward as only possible with associative entity without carrying any additional constraint.
多對多是相對直接的,只有在沒有任何附加約束的情況下,才可能具有關聯實體。
> class Passenger {}
> class Flight {}
> class Ticket {}> passenger1 = new Passenger();
> flight1 = new Flight();> ticket1 = new Ticket();
> ticket1.passenger = passenger1
> ticket1.flight = flight1;> flight2 = new Flight();> ticket2 = new Ticket();
> ticket2.passenger = passenger1
> ticket2.flight = flight2;
查詢 (Queries)
Queries is done with functional programming.
查詢是通過函數式編程完成的。
The runtime stores each instance into its class list like
driver1 = new Driver()
will be part ofDrivers
.運行時將每個實例存儲到其類列表中,例如
driver1 = new Driver()
將成為Drivers
一部分 。
一對一 (One-to-One)
> Drivers.filter( d=> d.state == "GA").filter( d => d.vehicle.year > 2010)
// Finds drivers in GA state with car younger than 2010
一對多 (One-to-Many)
> Orders.filter( o => o.price > 100 && o.customer.id == 192)
// Finds orders with bigger than $100 prize of customer with id 192
Other direction
其他方向
> Customers.find( c=> c.id == 192).orders.filter( o=>o.price > 100)
多對多 (Many-to-Many)
Tickets.filter( t => t.passenger.id == 6912 && t.flight.destination == "LA")
// Finds ticket of passenger with id 6912 for destination to FL
Reference: https://nucleoid.org/tutorial/
參考: https : //nucleoid.org/tutorial/
翻譯自: https://medium.com/nucleoid/data-relationships-in-nucleoid-e3837512d264
關系型數據庫的核心單元是
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/387844.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/387844.shtml 英文地址,請注明出處:http://en.pswp.cn/news/387844.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!