-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added relational lenses full tests * added travis config to run relational lens tests
- Loading branch information
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var db = database "links"; | ||
|
||
var albumsTable = | ||
table "albums" | ||
with (album: String, quantity: Int) | ||
tablekeys [["album"]] | ||
from db; | ||
|
||
var tracksTable = | ||
table "tracks" | ||
with (track: String, date: Int, rating: Int, album: String) | ||
tablekeys [["track", "album"]] | ||
from db; | ||
|
||
var albumsLens = lens albumsTable with { album -> quantity }; | ||
var tracksLens = lens tracksTable with { track -> date rating }; | ||
|
||
var joinedLens = lensjoin albumsLens with tracksLens on album delete_left; | ||
var droppedLens = lensdrop date determined by track default 2018 from joinedLens; | ||
var filteredLens = lensselect from droppedLens by quantity > 2; | ||
|
||
|
||
|
||
fun test() { | ||
var filtered = lensget filteredLens; | ||
|
||
assertEq(filtered, [ | ||
(album = "Wish", quantity = 5, rating = 4, track = "Trust"), | ||
(album = "Paris", quantity = 4, rating = 5, track = "Lovesong"), | ||
(album = "Show", quantity = 3, rating = 3, track = "Lullaby") | ||
]); | ||
|
||
# filter out all tracks named "Trust" and change Lullaby's rating to 4. | ||
var newTracks = [ | ||
(album = "Show", quantity = 3, rating = 4, track = "Lullaby"), | ||
(album = "Disintegration", quantity = 7, rating = 5, track = "Lovesong") | ||
]; | ||
|
||
lensput filteredLens with newTracks; | ||
|
||
var new = lensget filteredLens; | ||
assertEq(new, newTracks); | ||
|
||
assertEq(lensget tracksLens, [ | ||
(album = "Show", date = 1989, rating = 4, track = "Lullaby"), | ||
(album = "Galore", date = 1989, rating = 4, track = "Lullaby"), | ||
(album = "Disintegration", date = 1989, rating = 5, track = "Lovesong"), | ||
(album = "Galore", date = 1989, rating = 5, track = "Lovesong") | ||
]); | ||
assertEq(lensget albumsLens, [ | ||
(album = "Disintegration", quantity = 7), | ||
(album = "Wish", quantity = 5), | ||
(album = "Paris", quantity = 4), | ||
(album = "Galore", quantity = 1), | ||
(album = "Show", quantity = 3) | ||
]); | ||
|
||
lensput filteredLens with filtered; | ||
} | ||
|
||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var db = database "links"; | ||
|
||
var albumsTable = | ||
table "albums" | ||
with (album: String, quantity: Int) | ||
tablekeys [["album"]] | ||
from db; | ||
|
||
var tracksTable = | ||
table "tracks" | ||
with (track: String, date: Int, rating: Int, album: String) | ||
tablekeys [["track", "album"]] | ||
from db; | ||
|
||
var albumsLens = lens albumsTable with { album -> quantity }; | ||
var tracksLens = lens tracksTable with { track -> date rating }; | ||
|
||
var joinedLens = lensjoin albumsLens with tracksLens on album delete_left; | ||
|
||
fun test() { | ||
var old = lensget joinedLens; | ||
|
||
var newTracks = [ | ||
(album = "Wish", date = 1992, quantity = 5, rating = 4, track = "Trust"), | ||
(track="It's the end of the world as we know it", | ||
rating=5, album="Eponymous", date=1988, quantity=42), | ||
(album = "Show", date = 1989, quantity = 3, rating = 3, track = "Lullaby"), | ||
(album = "Galore", date = 1989, quantity = 1, rating = 3, track = "Lullaby"), | ||
(album = "Paris", date = 1989, quantity = 4, rating = 5, track = "Lovesong"), | ||
(album = "Galore", date = 1989, quantity = 1, rating = 5, track = "Lovesong") | ||
]; | ||
|
||
lensput joinedLens with newTracks; | ||
|
||
assertEq(lensget joinedLens, newTracks); | ||
assertEq(lensget albumsLens, [ | ||
(album = "Eponymous", quantity = 42), | ||
(album = "Disintegration", quantity = 7), | ||
(album = "Wish", quantity = 5), | ||
(album = "Paris", quantity = 4), | ||
(album = "Galore", quantity = 1), | ||
(album = "Show", quantity = 3) | ||
]); | ||
assertEq(lensget tracksLens, [ | ||
(album = "Wish", date = 1992, rating = 4, track = "Trust"), | ||
(album = "Eponymous", date = 1988, rating = 5, track = "It's the end of the world as we know it"), | ||
(album = "Show", date = 1989, rating = 3, track = "Lullaby"), | ||
(album = "Galore", date = 1989, rating = 3, track = "Lullaby"), | ||
(album = "Paris", date = 1989, rating = 5, track = "Lovesong"), | ||
(album = "Galore", date = 1989, rating = 5, track = "Lovesong") | ||
]); | ||
|
||
lensput joinedLens with old; | ||
} | ||
|
||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
database_driver=postgresql | ||
database_args=localhost:5432::links | ||
show_pre_sugar_typing=off | ||
relax_query_type_constraint=on | ||
relational_lenses=on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
DROP TABLE IF EXISTS Albums; | ||
|
||
CREATE TABLE Albums ( | ||
Album VARCHAR(50) NOT NULL, | ||
Quantity INT NOT NULL, | ||
PRIMARY KEY (Album) | ||
); | ||
|
||
DROP TABLE IF EXISTS Tracks; | ||
|
||
CREATE TABLE Tracks ( | ||
Track VARCHAR(50) NOT NULL, | ||
Date INT NOT NULL, | ||
Rating INT NOT NULL, | ||
Album VARCHAR(50) NOT NULL, | ||
PRIMARY KEY (Track, Album) | ||
); | ||
|
||
INSERT INTO Albums (Album, Quantity) VALUES | ||
('Disintegration', 6), | ||
('Show', 3), | ||
('Galore', 1), | ||
('Paris', 4), | ||
('Wish', 5); | ||
|
||
INSERT INTO Tracks (Track, Date, Rating, Album) VALUES | ||
('Lullaby', 1989, 3, 'Galore'), | ||
('Lullaby', 1989, 3, 'Show'), | ||
('Lovesong', 1989, 5, 'Galore'), | ||
('Lovesong', 1989, 5, 'Paris'), | ||
('Trust', 1992, 4, 'Wish'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
01_cds | ||
02_cds |