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.
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
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
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.
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
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...
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
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:
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
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:
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
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
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
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
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
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.
Video #3 is out:
> [https://www.youtube.com/watch?v=R1FOKpg5UNs](https://www.youtube.com/watch?v=R1FOKpg5UNs)
@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
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
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
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.
Thanks for the suggestions!
Both the new game (smalltrek) and the "Add Game" form are up on the
nimgame.online website.
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
@Divy, that is a great idea. I'll add such a form this weekend when I'm adding
the smalltrek game.
@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.
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)/
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
doh! Looking at old code of mine, I should have recalled that.
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.
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?
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. :)
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
> 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
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,
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
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
(disclaimer: I'm the author of BSON)
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
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
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
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
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.
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
It's confirmed finally: I will be at FOSDEM 2020. I'll be sure to visit the
devroom on Sunday.
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
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
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. :)
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.
* *
... 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.
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
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
> 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 , :
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
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.
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
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
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].
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]
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 $.
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
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
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
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?
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
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
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.
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
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
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
@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.
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 =
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.
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.
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
Thanks! I'll change the libraries to match up with these guidelines on the next
release.
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
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?
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
78 matches
Mail list logo