Re: Connection-Pooling Compile-Time ORM

2020-07-03 Thread JohnAD
Can't help myself: const data: SqlQuery = sqls: SELECT Pet.name FROM Pet INNER JOIN House ON House.id = Pet.houseId WHERE House.country = "CA" Run That would be really clean.

Re: Connection-Pooling Compile-Time ORM

2020-07-03 Thread JohnAD
To followup on @Variount 's question. Is the ORM goal to be something like: type Pet = object {. tableName: "pets" .} name: string age: int {. fieldName: "age_years" .} const data: SqlQuery = sqls: select Pet.* `from` Pet where Peg.age

Re: Connection-Pooling Compile-Time ORM

2020-07-03 Thread JohnAD
As to case, in this particular application, one could have a version that supports the typical styling guidelines for SQL statements. SELECT blah FROM xyz WHERE zin=4 Run could be DSL'd as: const data: SqlQuery = sqls: SELECT "blah" FROM

Re: advanced `nim doc` use

2020-06-28 Thread JohnAD
Or, I could just give up and generate two html files and use the "exports" section at the bottom. Not the end of the world. Just curious if there is a work-around.

Re: advanced `nim doc` use

2020-06-28 Thread JohnAD
Are there any when conditions I could use just for documentation. Aka: when defined(docgen): type ABC = object ## this the fancy ABC object. Use it to track blah and stuff. blah: int else: import common # this imports the REAL type ABC for

Re: advanced `nim doc` use

2020-06-28 Thread JohnAD
The `--docInternal` simply documented the non-exported items also. But the items from `common.nim` still didn't make it. But..that option tells me I've not seen all the options yet. I'm off to hunt...

advanced `nim doc` use

2020-06-28 Thread JohnAD
I'm working on a library that is fairly long. After a single nim file reached about 2000 lines, I realized a refactoring is way over due. So I broke the file into four source files. And, in past projects, I could often abstract the subtending files so that there was no dependency on the main

Re: jester: one handler for several routes?

2020-06-19 Thread JohnAD
While not as flexible as @treeform 's solution, but if the naming allows for it, you could do a patterned naming. Either as a regex (see [https://github.com/dom96/jester#regex](https://github.com/dom96/jester#regex)) or simple pattern. For example: import jester routes:

Re: Using generic objects and inheritance at the same time.

2020-05-20 Thread JohnAD
Off-topic: is there the equivalent of a "when case"? I like that nim checks for missing scenarios when writing "case" statements. I like that nim allows for compile-time code decisions with "when" directives. Putting those together would be spiffy. Not a top-tier feature by any means, but it

Using generic objects and inheritance at the same time.

2020-05-20 Thread JohnAD
After many many hours of trying to make this work, I finally got it to go. I suspect I'm not the only person to struggle with this, so I figured I'd document the answer here. Rather than getting into theoreticals, let's just jump into code. Nim supports inheritance for objects. An example:

A good word for idiomatic nim?

2020-05-12 Thread JohnAD
This will be a fun/light post. The following is idiomatic to Nim: let myNumber = 3 + 9 Run whereas the following is not: let My_Number = `+`(3,9) Run Prior to my introduction to Python I really never cared much about being idiomatic; but

Call-for-Help: a 128-bit Decimal library expansion

2020-05-08 Thread JohnAD
I have just released a new decimal library for Nim that is based on the IEEE 754-2008 specification. [https://github.com/JohnAD/decimal128](https://github.com/JohnAD/decimal128) It has a pending PR for inclusion in the nimble directory. Examples of use: let a = newDecimal128

Re: Semantic grep, a very cool idea (currently mostly for Python)

2020-05-05 Thread JohnAD
I like the idea. I'll have to play with it sometime. I'm glad you linked the slides. I started by looking at the examples in `semgrep` repo, and they all showed semgrep through a docker; which makes sense for PHP/Python etc. But would be odd for a compiled language. I would think putting the

Re: Nim programming book for kids

2020-04-24 Thread JohnAD
I do both video and written books in other contexts (in fact I own a small book publishing company called Purple Squirrel Productions.) I would simply say that different people learn things differently. But I agree that YouTube videos can be boring for me. That is especially true of "do this

need for a decimal library?

2020-04-20 Thread JohnAD
In both * working on projects that involve financial transactions, and * maintaining the nim MongoDB libraries `mongopool` and `bson` which has a decimal type in addition to float, I've been tempted multiple times to build out a library for Nim that supports decimal numbers (base 10 math

Re: Video series: Making a WebSite with Nim

2020-04-20 Thread JohnAD
Yes, the code is at: > [https://github.com/JohnAD/bookclub](https://github.com/JohnAD/bookclub) There is a Release pointing to the commit made at the end of each episode.

Re: Video series: Making a WebSite with Nim

2020-04-20 Thread JohnAD
Video #3 is out: > [https://www.youtube.com/watch?v=R1FOKpg5UNs](https://www.youtube.com/watch?v=R1FOKpg5UNs)

Re: Where can I deploy a Nim web application? Is there a "NimAnywhere" yet?

2020-04-13 Thread JohnAD
@dom96 True. I run docker-compose for consistency and separation mostly. **consistency** It almost guarantees that the instance on my local laptop will be truly replicated on any instance I run on the cloud. My nginx configs always includes `*.localtest.me` support. Basically, I can test the

Re: Where can I deploy a Nim web application? Is there a "NimAnywhere" yet?

2020-04-11 Thread JohnAD
Myself, I use Digital Ocean for hosting, using docker-compose. I keep the source code (w/o credentials) for each site on separate private repos and put the results on a separate repo for the docker instance. Essentially, each website is compiled with C. I write a move.sh bash script to move

Re: Format() problem with Jester

2020-04-11 Thread JohnAD
I recognize this code. :) If you would like the original, I've been placing the website code after each section of the YouTube series at: [https://github.com/JohnAD/bookclub](https://github.com/JohnAD/bookclub) If you look at the releases, each release points to the commit for that part

Re: Video series: Making a WebSite with Nim

2020-03-26 Thread JohnAD
It took considerably longer than I intended to get the video #2 out. But it _is_ out now: > [https://www.youtube.com/watch?v=tz6av3o4XUI](https://www.youtube.com/watch?v=tz6av3o4XUI) Video 3 is written and should be posted this weekend.

Re: A 'made with Nim' website?!

2020-03-01 Thread JohnAD
Thanks for the suggestions! Both the new game (smalltrek) and the "Add Game" form are up on the nimgame.online website.

Re: Async web servers and database

2020-03-01 Thread JohnAD
An alternative is to have a pooled driver that is friendly to async. My MongoDb driver does this: `mongopool` (on nimble). Essentially, the connections to the database are pooled and used dynamically by the server threads. So no slow down at scale. With postgresql and mysql this is not as

Re: A 'made with Nim' website?!

2020-02-26 Thread JohnAD
@Divy, that is a great idea. I'll add such a form this weekend when I'm adding the smalltrek game.

Re: A 'made with Nim' website?!

2020-02-26 Thread JohnAD
@hyl I'm happy to add any nim javascript game. My searches on GitHub have not been very fruitful so far. Either games are not actually finished or they don't compile to Javascript. My incentive for making the site, in part, is to make it easier for future devs to find examples of nim js games.

Re: A 'made with Nim' website?!

2020-02-22 Thread JohnAD
Sounds like a useful resource. Be sure to post a link. In a similar manner, I've been slowly maintaining a website showcasing open-source nim javascript games: [https://nimgame.online](https://nimgame.online)/

Suggestions for performance-tracking a nim database driver?

2020-02-05 Thread JohnAD
So, for the `mongopool` MongoDB database driver, I'd like to create a set of performance benchmarks so that the impact of future code changes can be relatively measured. There is, AFAIK, no real means of reliably "mocking" a MongoDb server (esp. since I'm wanting to mock the performance

Re: conditional compilation from macro-generated code?

2020-01-25 Thread JohnAD
doh! Looking at old code of mine, I should have recalled that.

conditional compilation from macro-generated code?

2020-01-25 Thread JohnAD
if I do: var x:int if declared(joe): x = joe() else: x = 4 Run Essentially, that is conditional compilation: the existence or non-existence of "joe" is checked at compile time. All is good. If I use a macro to generate some code, that works also.

Re: conditional compilation from macro-generated code?

2020-01-25 Thread JohnAD
I guess the question would be: is there a good way for the macro itself to detect, using a string, if an identifier has been declared?

Re: Fizzbuzz game

2020-01-24 Thread JohnAD
saved 5 more: nim for i in 1..100: case i mod 15: of 0: echo "FizzBuzz" of 3,6,9,12: echo "Fizz" of 5,10: echo "Buzz" else: echo $i Run I'm going to stop now. Down these paths lay OCD madness. :)

Re: Fizzbuzz game

2020-01-24 Thread JohnAD
five characters saved: for i in 1..100: if i mod 15==0: echo "FizzBuzz" elif i mod 5==0: echo "Buzz" elif i mod 3==0: echo "Fizz" else: echo $i Run Of course, you could also then remove all the fancy spacing if

Re: future of htmlgen

2020-01-23 Thread JohnAD
> You can use any of the macro-based html-generating nimble libraries or create > your own html builder. Not sure why would you use something like moustache > when macros exist. There are pros and cons to each direction. I use the macro approach on one of my larger websites. It now takes 8

future of htmlgen

2020-01-23 Thread JohnAD
I'm about finished with production on my next YouTube video, which is about demonstrating some of the methods of generating the HTML views under Jester. They currently are: 1. simple string manipulation (aka `strutils`) 2. using `htmlgen` 3. using Source Code Filters 4. from nimble,

Video series: Making a WebSite with Nim

2020-01-17 Thread JohnAD
The first two episodes are up on YouTube. I hope to do about one a week; there will be at least nine of them in the end: > [https://www.youtube.com/playlist?list=PL6RpFCvmb5SGw7aJK1E4goBxpMK3NvkON](https://www.youtube.com/playlist?list=PL6RpFCvmb5SGw7aJK1E4goBxpMK3NvkON) On an adjacent topic: I

Re: Error converting json to types

2019-12-25 Thread JohnAD
BSON uses Extended Json (v2); and BSON does have a UTC Time/Date function. Granted, it converts to Time rather than DateTime. BSON also has marshalling support to/from objects. If interested in that: [https://nimble.directory/pkg/bson](https://nimble.directory/pkg/bson) Example of use with

Re: Error converting json to types

2019-12-25 Thread JohnAD
(disclaimer: I'm the author of BSON)

Re: Walking trees without recursive iterators

2019-12-18 Thread JohnAD
It is always possible to move a recursive algorithm to a non-recursive one; even avoiding psuedo-stacks or tail-recursion games. It is, ironically, something I enjoy doing because it is quite the intellectual puzzle sometimes. The toughest one I did was with the Negamax (Minimax with

interest in a decimal library

2019-12-14 Thread JohnAD
I'm about to expand the `BSON` protocol library to support 128-bit decimal numbers. But, to do that, I would need to write a 128-decimal decimal number support into Nim. So, I could either: 1. put the new data type directly into the `BSON` library, or 2. create a seperate 128-bit decimal

Re: interest in a decimal library

2019-12-14 Thread JohnAD
other notes: 1\. The library would be written such that it conforms to the BSON spec: * [https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst](https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst) Which uses the

Re: indentation

2019-12-14 Thread JohnAD
Nice font. A quick test with a nim sample: [https://d.pr/i/Cj8kSE](https://d.pr/i/Cj8kSE) I wonder if using a proportional font would further discourage me from doing any... proc myP( i: int, c: char ) Run ... space-alignment

Re: Editor support for Nim 1.0

2019-12-14 Thread JohnAD
I use SublimeText 3 also. While the Nim support is out of date and seems to have quirks, it does not actually cause me any problems.

confirming the purpose of `$` stringify operator

2019-12-13 Thread JohnAD
I'm about to make a few changes in some of my libraries and I'd like to ask the language devs a key question about the $ stringify operator. I want to make sure my libraries are following "nimish" convention as much as possible. So, my question: what is the specific purpose of the operator in

Re: FOSDEM Call for Participation

2019-11-21 Thread JohnAD
It's confirmed finally: I will be at FOSDEM 2020. I'll be sure to visit the devroom on Sunday.

the "type" of the curly-bracket structure

2019-11-16 Thread JohnAD
If I write a macro as such: macro `@@@`(x: typed): FancyType = # stuff goes here var a = @@@{"fromStruct": "blah", "sub": {"joe": 10}} Run All is good. Or if I do: macro `@@@`(x: Blork): FancyType = # stuff goes here let xyz

nimgame.online - open-source nim javascript games (and references to the source)

2019-11-14 Thread JohnAD
I was going to put up one of my games online anyway, so I figured I'd make it more educational: this could be an online repository of javascript nim games with links to the corresponding source code. Details at [https://nimgame.online](https://nimgame.online) If nothing else, it has two of my

Re: FOSDEM Call for Participation

2019-10-14 Thread JohnAD
I plan on attending the upcoming FOSDEM. While I'm not prepared to "present a talk"; I'm happy to volunteer my help in less-intense ways. :)

Research questions for open-source library authors re communicating with general users

2019-10-14 Thread JohnAD
I'm doing research for a possible startup where I'm writing a tool (in Nim) for supporting library repos. I also have a few libraries up on nimble.directory. So, I figured this forum might be a apt place to ask some open-ended research questions. If it is inappropriate, please let me know. * *

Re: Introducing Norm: a Nim ORM

2019-10-05 Thread JohnAD
... checked the range. `Time` is good to the year 292277026596 and presumably backwards that far. So, you will have to worry about the Y292277026K problem.

Re: Introducing Norm: a Nim ORM

2019-10-05 Thread JohnAD
In the expansion of `norm` to support mongodb that I'm developing, I've defaulted to only supporting `Time`. The `DateTime` type breaks things on so many levels, mostly because `DateTime()` generates a runtime error. Fortunately, the `Time` function, though based on the traditional Unix

Is it possible to detect context in relation to a threadvar?

2019-09-04 Thread JohnAD
I'm developing a library that maintains a global pool of resources that can be seen in both thread and non-threaded contexts. Rather than jump into great detail, let show this with a silly example: import strutils import jester var someGlobal: string = "value at the

Re: Jester question: passing gcsafe variable into routes

2019-08-29 Thread JohnAD
> To fix this to work with threads you should use a threadvar, and initialise > the DB connection in each thread. Ah, but that gets me back to 2 seconds delay per page. Just for fun; started diving in. I created a new element called `decorate`: decorate : beforeThread , :

Jester question: passing gcsafe variable into routes

2019-08-28 Thread JohnAD
I have a web project that uses an external database. I'm wanting to write the site in Nim using the jester library. One of the gotchas of the database, which I cannot control, is that though the database itself is very fast, establishing an authenticated connection to it takes about two

Re: nimongo and MongoDb.Atlas connection

2019-08-13 Thread JohnAD
Update for sake of completeness: MongoDb Inc. didn't work simply because they require SCRAM-SHA-256 auth encryption on the cheaper accounts. Nimongo seems to only support SCRAM-SHA-1 at the moment. So... it is not a conspiracy; simply a protocol mis-match for which I don't have a work-around.

Re: nimongo and MongoDb.Atlas connection

2019-08-13 Thread JohnAD
Never mind. While I am still curious as to what is needed to get it to work, I gave up and created an account at cloudclusters.io and it worked on the first try. Given the other providers are all running 3.x of MongoDb and they are running 4.0, I kind of wonder if MongoDb Inc. is running some

nimongo and MongoDb.Atlas connection

2019-08-12 Thread JohnAD
I've been using the pure nim nimongo library for a while and it has been very useful. I am attempting to get a project into full production and am wanting to move to a live database and am having trouble with that. Specifically, I have an account at mongodb.com (MongoDb Inc.'s Atlas) But I'm

Re: Problem with var objects and adding values to them

2019-08-07 Thread JohnAD
this can be solved with a converter. Add: converter fromBtoA(b: B): A = result = A(x = b.x) Run The y field will not be stored, of course, since X is a seq[A].

get a type via a string?

2019-07-19 Thread JohnAD
I'm writing a macro that parses over object types and generates various functions on it's fields. For the most part it works. However, I'm will likely encountering folks trying to do this: type ssnType = Option[int] type Person = object age: Option[int]

Re: timezone in unit tests

2019-07-14 Thread JohnAD
Thanks for the helpful work-around. Still can't test the $ function without manipulating an environment variable, but that isn't the end of the world is suppose. Perhaps, if I get motivated, I'll make a PR for a compiler variable for the times module that allows for an override for $.

timezone in unit tests

2019-07-13 Thread JohnAD
I'm writing a library that reads Time in and out of a database. As part of that, I am writing unit tests the output of $ for Time. $ does not take extra parameters by its nature. The problem is that $ generates a string in my local time zone. For myself, that kind of works. But if/when the

challenges with bool parameter on template

2019-07-07 Thread JohnAD
echo "never seen" Run I've been able to narrow down my problem scenario. A template with a bool parameter works normally except when pulled through getAst inside a macro. In that scenario, it seems to "become" an integer. I get the error: /home

can already defined types be modified at compile time with a macro?

2019-07-06 Thread JohnAD
I can write a macro that allows me to do this: my_macro_adds_age: type SomeType = object name: string let a = SomeType(name: "Bob", age: 30) Run No problem. But, I'm curious, is it even possible (and safe) to modify a type after the

International meetup or conference?

2019-06-21 Thread JohnAD
With the upcoming 1.0 release; are there any thought to having a developer/users meetup or conference? Perhaps a developer room at FOSDEM 2020?

Re: Future direction of db_* modules

2019-05-31 Thread JohnAD
thanks @mikra! I did a search in Nim issues and somehow didn't find that one. Araq mentioned possibly moving `ndb` to the standard library if it can act as a replacement for the db_* modules. I'll look into volunteering to help with development of `ndb`. I like what I see so far, especially

Future direction of db_* modules

2019-05-30 Thread JohnAD
rn-sql-server-what-is-a-null-value)/ Handling this correctly solves many odd border-case scenarios, especially with aggregation functions. * I mention my "nullable" database types library to be complete. I'm _not_ pushing for this. In fact, using that would require that nullable be added to

Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-14 Thread JohnAD
No need apologize! Holy cow ... how did I not know about `converter`? I've been coding Nim for over a year now and I just now learned of it. I will have to re-read the manuals again. I wonder if there are any other hidden nuggets I've missed.

Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-13 Thread JohnAD
If, for example, I were wanting to create a crazy new int type that stored its value as product of primes, and I was not concerned with performance, I could create my own pure nim type in a library. type intAP = object setOfPrimes: array[0..50, int] Run

Re: How do I trace procs/things back to the module they come from?

2018-07-25 Thread JohnAD
If you wish to get into the habit of it, you can also: from x import nil Run Then, in your code, reference `x.thing1` and `x.thing2`. Or, if the module name is really long or involves directory separation: from reallylongname/subdir/awesomelib as x

any value to a dynamiclists module to the public

2018-05-14 Thread JohnAD
Running down the rabbit hole of my earlier questions. I've decided to make the equivalent to a dynamic list as you would see in an interpreted language. Would such a module be of interest to the public? If not, I'll write a nice limited version for myself. Essentially, the following would be

Re: get "size" of a tuple at compile time?

2018-05-13 Thread JohnAD
@def, Thanks! In fact, now that I'm browsing the "system" module ... I do believe I'll be sitting back on the couch reading the "system" module doc in depth tonight.

Re: get "size" of a tuple at compile time?

2018-05-13 Thread JohnAD
Actually, since I'm bugging you all with a question, i'll jump into some detail for feedback: The framework is for turn-based games. A **Game** object handles "different" kinds of players. The default **ConsolePlayer** is a "human sitting at the text console". So, if var move =

get "size" of a tuple at compile time?

2018-05-13 Thread JohnAD
Is there a way to get number of elements inside a tuple? This is known at compile time, of course; as tuples are fixed structures. At first glance, this probably sounds like an odd request, but i'm writing macro for an inheritable framework with objects referencing other inheritable objects.

Re: Statistics for standard library usage

2018-05-03 Thread JohnAD
quick correction regarding my earlier post: apparently there is already one website for nimble packages: [https://nimble.directory](https://nimble.directory)/ I just happened to come across it via a random google query. I don't see it referenced on nim-lang.org. Or even on the packages repo.

Re: Statistics for standard library usage

2018-05-01 Thread JohnAD
Adding a short opinion regarding what should be in the standard library for v1.0. Keep in mind my background is mostly python, however, I'm still a newb with Nim. One of Python's selling points is the large standard library that is distributed. But one of it's flaws, however, is that it only

Re: idiomatic name for object setup

2018-05-01 Thread JohnAD
Thanks! I'll change the libraries to match up with these guidelines on the next release.

clarification: overloading is strictly on parameter types?

2018-04-27 Thread JohnAD
Just a quick point of clarification: is it correct that nim can only do overloading in terms of parameter types and ignores the return type? Aka, the following example code would generate a compiler error: proc by_two(val: int): int = result = val * 2 proc

Re: [RFC] Adding @ prefix (or similar) to import

2018-04-27 Thread JohnAD
Araq, I like your idea even better. I'm not involved in the compiler coding...is this easily implemented while keeping the method and data separation underneath?

[RFC] Adding @ prefix (or similar) to import

2018-04-27 Thread JohnAD
As we all know, nim seperates the procedures that operate on an object from the data of the object itself. I understand the thinking and largely agree with it. However, a side-effect of this is that when importing an object from a module, it is difficult to control what is being imported. Such