razetime / ngn-k-tutorial

An ngn/k tutorial.
https://razetime.github.io/ngn-k-tutorial/
195 stars 22 forks source link

Practical examples (http, database commands, i/o) #4

Closed secwang closed 9 months ago

razetime commented 2 years ago

A description would be helpful. I'm not sure what exactly would be in a http example.

Do you want a tutorial on making POST and GET requests in K?

secwang commented 2 years ago

Yes, I want some methods like Q's hg and hp After all, in the use of engineering, if this thing can handle http requests well, and some basic json packaging methods, then it can be directly used in engineering. https://code.kx.com/q/ref/dotq/#qhg-http-get

secwang commented 2 years ago

The other thing that I think is useful to the public Try to describe sql's equivalent k query, because in native k, we use dict to simulate table, and all sql should be equivalent to dict operations. I remember ngn said that this is why ngnk doesn't add sql layer. But this transformation of abstraction is useful for most engineers, who are not familiar with this non-sql abstraction.

razetime commented 2 years ago

Hm, these do seem like good ideas. Maybe I will add them to the tables section. I think I might add some appendices to add other content that's not ngn/k only.

secwang commented 2 years ago

Yes, I believe that the vast majority of kdb+ users are using the sql function of k, that is, adding, deleting and querying using dict or table. This is the core factor in my opinion. The second is the ability of io. Kdb+ does very well, but these are also the two core competencies. I think ngnk has the potential to be used in a production environment. It's so sexy.

secwang commented 2 years ago
create table
a:+`a`b`c!3 3#!9

insert sql
a,:`a`b`c!9,10,11

select
select first line of table
a@0 or a 0

find if equal
a@a[`a]?0

find use where
(1<)#a
,2
(1<)_a
0 1

a@(1<)_a[`a]

update
@[x;i;:;v] as "update value at x[i] with v"
but you could think of : as "right", i.e. return the right value

@[a;0;:;(12,13,14)]

delete
delete is reverse select
a@(1<)_a[`a]

---
take some note for sql in ngnk
razetime commented 1 year ago

After some thinking, I think actual database work is not something that ngn/k intends to achieve.

I've decided to talk about table support though. With serialization and deserialization, it should be enough to show how to store tables in files and retrieve them for manipulation. The other examples I have taken into consideration, and they will be added in the future if i can learn how to make it work.

secwang commented 1 year ago

I found that six months ago, ngnk updated the relevant code of extends. I should be able to use c to extend ngn/k. I tested it, but it didn't pass completely, so more commonly used scenarios can be handled by extends.

razetime commented 9 months ago

in the newly added chapter 15, some table related functionality is discussed.

razetime commented 9 months ago

I've decided the rest are not going to be included here, since they mostly involve C programming and less K.