-
Notifications
You must be signed in to change notification settings - Fork 11
/
samples.js
69 lines (65 loc) · 3.16 KB
/
samples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-disable no-unused-vars */
/* global cds */ ;async () => {
// Run the following line by line in
//$ npm add git+https://github.com/cap-js/cds-dbs.git
//$ cds watch --profile better-sqlite
//$ cds repl --profile better-sqlite
var { server } = await cds.test('@capire/bookshop'),
{ Books, Authors } = cds.entities
await INSERT.into(Books).entries({ title: 'Unwritten Book' })
await INSERT.into(Authors).entries({ name: 'Upcoming Author' })
await SELECT`from ${Books} { title as book, author.name as author, genre.name as genre }`
await SELECT`from ${Authors} { books.title as book, name as author, books.genre.name as genre }`
await SELECT`from ${Books} { title as book, author[ID<170].name as author, genre.name as genre }`
await SELECT`from ${Books} { title as book, author.name as author, genre.name as genre }`.where({
'author.name': { like: 'Ed%' },
or: { 'author.ID': 170 },
})
await SELECT`from ${Books} { title as book, author.name as author, genre.name as genre } where author.name like 'Ed%' or author.ID=170`
await SELECT`from ${Books}:author[name like 'Ed%' or ID=170] { books.title as book, name as author, books.genre.name as genre }`
await SELECT`from ${Books}:author[150] { books.title as book, name as author, books.genre.name as genre }`
await SELECT`from ${Authors} { ID, name, books { ID, title }}`
await SELECT`from ${Authors} { ID, name, books { ID, title, genre { ID, name }}}`
await SELECT`from ${Authors} { ID, name, books.genre { ID, name }}`
await SELECT`from ${Authors} { ID, name, books as some_books { ID, title, genre.name as genre }}`
await SELECT`from ${Authors} { ID, name, books[genre.ID=11] as dramatic_books { ID, title, genre.name as genre }}`
await SELECT`from ${Authors} { ID, name, books.genre[name!='Drama'] as no_drama_books_count { count(*) as sum }}`
await SELECT`from ${Authors} { books.genre.ID }`
await SELECT`from ${Authors} { books.genre }`
await SELECT`from ${Authors} { books.genre.name }`
await SELECT.localized('ID', 'title', 'author.name', 'descr').from(Books)
await INSERT({ title: 'Boo', foo: 'bar' }).into(Books)
await UPSERT.into(Books).columns('ID', 'title').rows([201, 'Sturmhöhe'])
await SELECT.from(Books, b => {
b.ID, b.title
})
server.close()
let q = {
SELECT: {
localized: true,
from: {
join: 'left',
args: [
{ ref: ['sap.capire.bookshop.Books'], as: 'Books' },
{ ref: ['sap.capire.bookshop.Authors'], as: 'author' },
],
on: [{ ref: ['author', 'ID'] }, '=', { ref: ['Books', 'author_ID'] }],
},
columns: [{ ref: ['Books', 'ID'] }, { ref: ['Books', 'title'] }, { ref: ['author', 'name'], as: 'author_name' }],
},
}
let lq1 = {
SELECT: {
localized: true,
from: {
join: 'left',
args: [
{ ref: ['localized.sap.capire.bookshop.Books'], as: 'Books' },
{ ref: ['localized.sap.capire.bookshop.Authors'], as: 'author' },
],
on: [{ ref: ['author', 'ID'] }, '=', { ref: ['Books', 'author_ID'] }],
},
columns: [{ ref: ['Books', 'ID'] }, { ref: ['Books', 'title'] }, { ref: ['author', 'name'], as: 'author_name' }],
},
}
}