Re: Norm 2.0.0
I do find this syntax nice but the problem is it doesn't work 😩 I'm not sure why but dup had trouble working inside macros. Maybe because it's a macro itself and the macro resolution algorithm works in such a way that by the time outer macro is resolved the inner one is not, so we're getting a TypeError with code like this.
Re: Norm 2.0.0
@reneha @cumulonimbus Added an issue, feel free to discuss there: [https://github.com/moigagoo/norm/issues/73](https://github.com/moigagoo/norm/issues/73)
Re: Norm 2.0.0
Where would you store it? In the Model type? Or in a separate global variable?
Re: Norm 2.0.0
You are right, update is a far from optimal operation in the current implementation. In fact, it's even worse than you've described, because all related objects are updated too. So for a single object, not only all its columns are updated but also all columns of all its related objects even if they didn't change. I don't have plans to optimize it, simply because I don't know what the best way to do that is. I can see two solutions: 1\. Before updating, run select and compare the two objects. See which fields changed and generate a selective update. This solution means that an extra query is performed for each update query, which pays off with large DBs but imposes redundant overhead for smaller ones. But since we're doing extra queries to update related objects, it may be not a bad solution. 2\. Override field assignment to track which fields were updated, store that information, and use it to generate a selective update. This is quite optimal but assignment is not the only way to modify an object, so it may now cover all cases. Also, it requires some additional state, I don't like that. Feel free to create an issue and suggest solutions. This is a potentially major bottleneck. PRs are welcome too.
Re: Norm 2.0.0
That almost made me cry :-) Thanks, it means a lot, really does 🙏 Did you have a chance to try out the new version? > (And if you want a challenge, help us transition the NimForum to using Norm > :D) First, I need to update Norman, that's essential. But when I'm done, this sounds like a fun challenge!
Re: Norm 2.0.0
> I can imagine migrations that don't change the schema. Data migrations can be done with `select` and `update`. Although data migrations are generally unwanted.
Re: Norm 2.0.0
> I'm not sure about the removal of migrations though, that will make it very > hard to create any libraries/"plugins" as there won't be a standardized way > of moving between versions. You still can run migrations, you just write them in pure SQL. Migrations are hard. Even if we take the most trivial case, adding a column, how do you populate its value for existing records? Should there be a default value? What if that value should be calculated for each record? Should it be NULL? Should it be the SQL representation of the default value of the respective Nim type? If we want to cover that with a proc, inevitably, calling this proc will look something like this: dbConn.addColumn(newUser(), "newColumn", default = "0") Run which, I believe, is just a harder to read version of this: dbConn.exec("ALTER TABLE User ADD COLUMN newColumn DEFAULT 0") Run > My experience is only really with Django's ORM though, so I might be missing > something Django ORM generates migrations automatically, which is really awesome. However, this is not the only way. In RoR, for example, you just write migrations in SQL. Generating migrations automatically is possible, but it's also a lot of work. I don't think I can do that.
Re: Norm 2.0.0
> it is helpful to have a tracking of which schema is in the database and which > one is expected by the code. [Norman](https://moigagoo.github.io/norman/norman.html) is a migration manager for Norm. It lets you apply and undo migrations, preserving order. I have to update it for Norm 2, possibly rewriting it since Norm has changed a lot. As of now, it just stores the name of the last applied migration in a file called `.last`. I'd rather store that information in the DB, but that requires more work. Also, I find your idea with hashes really interesting.
Re: Norm 2.0.0
> Doesn't this just waste performance creating a duplicate object that's going > to be discarded? To insert a row, you must first instantiate a model to hold the data for that row. So, either way, you're creating an object, you can't avoid that. The problem is that sometimes you don't care about that object. You need it just to do this one DB operation, like insert. And if you create those objects with `var`, they persist after your operation is done. This code sample demonstrates how you can get the object without introducing throwaway variables. Also, I don't think it has any negative effect on performance. It does allocate memory for the object, but, as I said. there's no way around that.
Re: Norm 2.0.0
Lessons learned: 1\. **Instances over typedescs.** With Norm 1, I inspected typedescs to generate SQL queries. To do that, I had to implement an intermediate representation layer for object definitions. This gave me more or less simple API to inspect and modify object definitions at compile time, but the price was increased overall complexity and, not importantly, inability to work with types. Since I had to inspect the code before the types were resolved, I had to use cringey techniques to map Nim types to SQL types, like converting the type to a string and comparing that to a different string. Using macros everywhere also took its toll, especially in my case where I'd have a macro generating a macro generating a template generating a proc. At some point, this complexity became unbearable as I couldn't even understand why my code works under some conditions and doesn't under others. Working with instances, in the other hand, is a breeze. Since it's an instance, it's guaranteed to have all its fields initialized and typed, which makes it trivial to inspect. Even for nested objects. And to insert `id` field into models, I don't have to inject nodes into nodes with macros, I can just use inheritance. 2\. **Ref objects over value objects.** I never really understood why one would need ref types at all. I mean, I read the docs and got the theory, but I never had a situation where switching to ref types would make a difference, so why type more and bother with those defers? And then this “a-ha” moment came when I really got it that models should be ref objects. Ref objects better reflect the relations between rows. 3\. **Explicit over implicit.** DB conn now has to be explicitly passed to DB procs, whereas previously, it was created implicitly in `withDb` blocks using credentials from `db` macro. The new approach allows the developer to utilize multiple connections in an obvious way, without ugly hacks (looking at you, `withCustomDb`). 4\. **Better safe than sorry.** I've deliberately removed the migration capabilities like add column, remove, rename table, etc. Turns out, migrations are never trivial, and it's always better to just write SQL manually than to try to automate it somehow. 5\. **Nim 's ``with`` and ``dup`` are awesome.** In Norm 1, I had this `withDb` macro that created an implicit DbConn for its scope. Now, I can do `with db` which is almost the same but better, because it allows to outplace not only the DB connection, but a model or a sequence of models. This makes for short, readable code, which at the same time has it all on the surface. It's explicit and clear. `dup` makes it simple to avoid creating mutating and not mutating variants of the same proc. Norm 2 has only mutating procs, and if you need an immutable variable, just `dup` your model. I wish I would deref or at least print the result of a `dup` block, and I wish I could use `with` with more than one argument. Something like: with db, obj: select("age > ", 40) delete Run
Norm 2.0.0
Hi all! It is my great pleasure to announce Norm version 2.0.0 🎉 I've rewritten in from scratch, because the previous architecture turned out to have unsolvable issues. There's zero backward compatibility, so if you've never used Norm before, just start using the new version and don't bother looking and previous versions, and if you do use Norm already, I'm afraid you'll have to rewrite your code. But this sacrifice is not in vain! Norm 2.0.0 is much more production ready. It finally solves the n+1 problem, it lets you easily connect to as many DB connections as you want, and you finally can have your models anywhere you like. The behavior of DB procs is now more predictable, there are no more magic object construction on the fly. The syntax is now more explicit. To learn the new Norm, [visit the docs](https://moigagoo.github.io/norm/norm.html). And just to give you the taste of the new, Nim 1.2.0-driven API, here's how you filter and update rows (taken from [tsqlitesugar.nim](https://github.com/moigagoo/norm/blob/develop/tests/tsqlitesugar.nim#L40)): discard @[newToy()].dup: dbConn.select("price > ?", 50) apply(doublePrice) dbConn.update Run
Re: Nimble Directory Redesign
Hey, I see the new design had been released! Looks great, thanks! 🙌
Re: Nimble Directory Redesign
Just want to say thank you for developing and maintaining Nimble directory. Use it all the time. 🙏
Re: Change Nim colour on GitHub
I think yellow is the way to go, just gotta find a different shade that passes the proximity test. Maybe more orange would do.
Get pragma value from object fields
What's the best way to get a pragma value for each object field? We have getCustomPragmaVal which accepts untyped. We also have fieldPairs which returns field names as strings. But there's no way to call getCustomPragmaVal knowing only the field name. The best solution I came up with is macro dot that takes an object and a string and spits a dotExpr. Then I pass that to getCustomPragmaVal. While that works, it has its limitations. Like, somehow I can't use it on procs in some cases, have to use templates. I'm also having issues with importing that macro. Is there a better pattern maybe?
Re: A good word for idiomatic nim?
Hochnimisch.
Re: Unicode support for Windows 10 console
You're discovering new platforms I see :-)
Re: Javascript browser backend: cannot include more than a single nim compiled source ?
Try using webpack to ship your Nim modules: [https://github.com/idle-z/nim-loader](https://github.com/idle-z/nim-loader)
Re: Finally, I can do functional programming on tiny embedded systems
Or having a talk at the upcoming online Nim conference.
Re: Idea: Nim Online Conference
I have a topic request: practical hot code reloading. So far, I couldn't make it work for backend or frontend code. Not that I spent too much time trying, but I believe it should just work. If someone could show how to make it just work on a simple but practical example, that would be great.
Re: Where can I deploy a Nim web application? Is there a "NimAnywhere" yet?
For frontend, Karax is the way to go. For backend, there are at least Jester and Rosencrantz. There's no Nim-sponsored hosting solution, you can pick anyone you like. I used to use Zeit when they offered Docker deployments. People say Heroku is nice.s
Re: Custom default for type
Thanks for the clarification! I always thought the RFC was about the fancy syntax for default values, not the fundamental ability to set them; that I assumed had been possible somehow. Oh well, I'll use an explicit init proc then.
Custom default for type
Hi! How do I set a default value for a type that doesn't have any? For example, an object or DateTime? I know there's `default` proc that gets the default value for a given type but I couldn't figure out how to use it.
Re: Idea: Nim Online Conference
I truly believe this is a fantastic idea, and we should make it happen. However, it seems like the thread stagnated. @Araq @dom96 maybe announce this in an official blog post?
Re: Idea: Nim Online Conference
Replaced the heading with bold text :-) Sure, Google Form is nice. Maybe, a Google Spreadsheet would do too.
Re: Idea: Nim Online Conference
I suggest we list topics in this thread in the format: Title = Run Brief description. One post—one topic. Votes for talks is done with ❤. I'll start by reformatting my own post.
Re: Idea: Nim Online Conference
Such a great idea, Andreas! I would like to showcase Nim for web with a complete chat example. I've done this talk at a local frontend conference, and it went pretty well, despite me failing to run the app at the end (I promise to fix it this time 😀). I'll cover Karax, WebSockets, and JS FFI.
Re: Introducing Norm: a Nim ORM
I'm proud to announce the first release of **Norman** , the migration manager for Norm: [https://moigagoo.github.io/norman/norman.html](https://moigagoo.github.io/norman/norman.html) With Norman, you can keep your DB config separate from the models in a project config and generate, apply and undo migrations. There are no tests at the moment, but they're on the way. Feel free to add Norman to your existing projects that use Norm, it should improve your developer experience.
Re: Why does `setCommand` exist?
No, these are completely different. The first one runs `nim js`, the second one `nim c -d:js`.
Re: Nim Compiling to js
To compile Nim to JS, run `nim js myfile.nim`, simple as that. To use modules from npm, use jsffi module ([https://nim-lang.org/docs/jsffi.html](https://nim-lang.org/docs/jsffi.html)) and Webpack with Nim loader ([https://github.com/bmollot/nim-loade)](https://github.com/bmollot/nim-loade\)). I tried it, works really well.
Re: Another micro web framework Prologue
I have a vision of Norm evolving to a compete framework someday. The ORM is there, the migration manager is underway, we can then add a GraphQL wrapper around Norm and add a layer for easy websocket communication between Karax frontend and e.g. Jester or Rosencrantz backend.
Re: Is it possible to see sql executed?
If you use Norm, you can use logging module to log all generated queries, just add import logging; addHandler newConsoleLogger()
Re: IntelliJ / Netbeans plugin for Nim
I'm using it with Sublime Text. It more or less works, but there's one really nasty issue: it won't see my local modules. So, I'm having a ton of errors all the time.
Re: Error compiling Rosencrantz with --gc:arc
Try completely removing your installation and installing Nim with choosenim. It will show what needs to be added to PATH during installation.
Re: How do I extract a particular block from an external module?
Thanks! This is exactly what I was looking for. I wish there was a way to mark the thread resolved.
Re: How do I extract a particular block from an external module?
The proposed solution works even without the intermediate template. If the arg type is typed then the content of the included file is passed to the macro and not the include statement. However, there's still a problem with it. If the included module contains macros, they are expanded before being passed to the macro. So I can't examine the macros declared in the included module, only the code generated from them. And for my specific task, I do need to find a particular macro block. I couldn't find anything like rawInclude or literalInclude. Maybe anyone could point to the right thing?
Re: How do I extract a particular block from an external module?
Now I'm even more confused. Tried this simple code: import macros macro foo(body: untyped): untyped = echo treeRepr body foo: var x = 123 Run This won't print anything to stdout. I could swear it should print the tree representation of `var x = 123`.
Re: How do I extract a particular block from an external module?
Thanks for the tip! This won't compile unfortunately: Error: unhandled exception: 'ident' is not accessible using discriminant 'kind' of type 'TNode' [FieldError]
Re: Nimble install local package.
You don't install nimble files, you install packages. Nimble file is just meta for a package. So downloading the file alone won't do. When you've cloned the repo, you can run either nimble install` or `nimble develop in the repo folder to install the package or install in development mode respectively.
How do I extract a particular block from an external module?
I need to find a db block in a module and copy it entirely to a new file. So, I basically need a way to pass a module's code to a macro where I'll iterate over its nodes to find the necessary one. So far, I haven't found a way do so. Naïve attempts like this one don't work, since I'm getting the tree of the include statement and not the included module: dumpTree: include anothermodule.nim Run Of course, I could always treat the module as a text file and just look for patterns, but this looks like a poor solution. There must be a better way.
Re: Introducing --gc:arc
Despite my fears, the entire Norm test suite runs in Nim devel with --gc:arc! To make it happen, only [a few minor code changes](https://github.com/moigagoo/norm/commit/551e11720b6a3aba75f02b4d43535f7b5d6efcde) were necessary. The future is now 😎
Re: Introducing Norm: a Nim ORM
> Did you think, open several connections > so if yes you can have a > transactional connection and a logical connection only for reading ... You can connect to several DBs with [withDb and withCustomDb](https://moigagoo.github.io/norm/norm.html#reference-guide-connection), which allows you to use one connection for reading and another for writing. > Did you think, open several connections You mean connection pool? There's an [open issue](https://github.com/moigagoo/norm/issues/50) for it, but I'm not planning on taking on it any time soon. I plan to focus on the migration manager for Norm.
Re: Overloaded proc dispatch won't work with object type
Thanks for the suggestion! Unfortunately, even the hack with generics didn't work in my case. Probably because one of those procs is calling the other, which causes this: `` Error: expression 'insert(obj, force)' has no type (or is ambiguous)`` Had to add a differently named proc: [https://github.com/moigagoo/norm/blob/feature/58_insert_for_immutable_objects/src/norm/sqlite.nim#L170](https://github.com/moigagoo/norm/blob/feature/58_insert_for_immutable_objects/src/norm/sqlite.nim#L170) Will report the issue to Nim.
Overloaded proc dispatch won't work with object type
Hi! I've got this weird behavior with overloading, could anyone please advise if it's a bug? INim 0.4.1 Nim Compiler Version 1.0.6 [Windows: amd64] at C:\Users\moigagoo\.nimble\bin\nim.exe nim> proc foo(x: object): int = x.i*2 nim> proc foo(x: var object) = x.i*=2 nim> type Foo = object i: int nim> let x = Foo(i: 3) nim> var y = Foo(i: 4) nim> echo foo(x) 6 nim> foo(y) Error: ambiguous call; both inim_1580414387.foo(x: object) [declared in C:\Users\moigagoo\AppData\Local\Temp\inim_1580414387.nim(3, 6)] and inim_1580414387.foo(x: var object) [declared in C:\Users\moigagoo\AppData\Local\Temp\inim_1580414387.nim(4, 6)] match for: (Foo) Run Why can't the compiler properly find the proc to call? It works with other types but not object.
Re: Introducing Norm: a Nim ORM
It is my great pleasure to announce Norm version 1.1.0 release: [https://moigagoo.github.io/norm/changelog.html](https://moigagoo.github.io/norm/changelog.html) The biggest change addition are the procs to write migrations. With those in place, I can focus on writing a migration manager that will make Norm even more useful for real life usage.
Docgen is underdocumented, requesting assistance
I want to use Nim's built-in documentation generating facilities to generates the docs for Norm: [https://moigagoo.github.io/norm](https://moigagoo.github.io/norm)/ However, there're issues I'm facing and cannot find the solution for. 1\. How to I generate an index link Nim's own [https://nim-lang.org/docs/theindex.html](https://nim-lang.org/docs/theindex.html) ? My index built with "nim buildIndex" looks quite poor in comparison: [https://moigagoo.github.io/norm/api/theindex.html](https://moigagoo.github.io/norm/api/theindex.html) Why does mine not show the modules and stuff? How does Nim put the module name at the top of every page, e.g. [https://nim-lang.org/docs/math.html](https://nim-lang.org/docs/math.html)? 2\. How do I generate TOC with rst2html? It's included in the generated docs if you call `nim doc` but not included if you call `nim rst2html`. 3\. Why is a submodule ignored by `nim doc`` command? ``sqlite`` folder is generated https://github.com/moigagoo/norm/tree/gh-pages/api/norm but ``postgres` is not, although they both exist in the code: [https://github.com/moigagoo/norm/tree/develop/src/norm](https://github.com/moigagoo/norm/tree/develop/src/norm) Here are the commands I'm calling to generate the docs: [https://github.com/moigagoo/norm/blob/feature/docs/norm.nimble#L15](https://github.com/moigagoo/norm/blob/feature/docs/norm.nimble#L15)
Re: Introducing --gc:arc
First, congrats! Seems like an important milestone, even if there's much to be done ahead. Second, what does arc in Nim mean for us mortals? Will compiling or running programs become faster? Will we have to use a different mechanism to get type information now that typeinfo is unavailable with arc? Is this information going to be different? Will we have to use new language constructs like sink and lent, whatever they mean? Is this a huge change for Nim under the hood or is just yet another gc option? Thanks, and Merry Christmas!
Re: indentation
What font are you using?
Re: when to use 'ref object' vs plain 'object'
Why does the second variant work when there's now `new` call? Shouldn't we see an illegal storage access error?
Re: Karax Components
Could you please elaborate? How to I store state of a VComponent and access it from other components?
Re: Karax Components
Thanks for the sample! Do you use this xName naming convention to make procs look more like types? Makes sense, just clarifying. Also, how would you handle state in your app model?
Karax Components
I've tried exploring component-based architecture in Karax once: [https://moigagoo.svbtle.com/exploring-karax](https://moigagoo.svbtle.com/exploring-karax) However, I now see there is VCompoment type in Karax and there are examples/tests that demonstrate its usage. Is this the official way to have components in Karax now? Is there any project I could look at built with these components? There's so little information available in Karax repo, the docs don't exist, and there's no sample project. It's a shame, Karax deserves better.
Re: Jester performance on FreeBSD is 1/10 of that on Linux
Could this be because Jester uses HttpBeast in Linux and builtin server on FreeBSD?
Re: Nim Podcast
Well I have the raw recordings somewhere on OneDrive. I can share a link if you want. Podcast is a great idea but I underestimated how much time and effort it requires.
Re: Introducing Norm: a Nim ORM
I just want to clarify that there's no problem with plain Datetime, m just init it explicitly like I do in tests and norm-sample-webapp. It's none Datetime that is the real issue.
Re: Introducing Norm: a Nim ORM
What are the types of your model fields? I'm getting these warnings when using Option[Datetime] because Datetime doesn't have a default value. To make things worse, you can't solve it even with manual initialization: `none Datetime` still doesn't initialize a Datetime object which throws the warning.
Re: Lambdas?
I don't think so: [https://hub.docker.com/_/ubuntu?tab=tags](https://hub.docker.com/_/ubuntu?tab=tags) They do have devel tag (I'm using that BTW) but it means that this is the development version of Ubuntu, i.e. eoan, not that it contains some packages for developers. So, I have to install GCC and wget manually: [https://github.com/moigagoo/nimage/blob/develop/flavors/slim.nim#L8](https://github.com/moigagoo/nimage/blob/develop/flavors/slim.nim#L8)
Re: Nim source size
Base images for Ubuntu and Alpine don't include GCC ¯_(ツ)_/¯
Re: Nim source size
These 19 MB probably don't include GCC and git and curl and other packages necessary to build Nim.
Re: Nim source size
Turns out, you can't remove the docs: /nim/compiler/commands.nim(61, 16) Error: cannot open file: ../doc/basicopt.txt Run
Re: Nim source size
Removed `c_code` from the Docker images, which got them **almost three times** thinner, from 1.3 GB to 527 MB. Thanks, @charlieH!
Re: Nim source size
If you find a way to reduce the installment size, please consider contributing to the Docker images at moigagoo/nimage.
Re: Compiling?
Nim only does the Nim code to C | C++ | JS code transformation. C | C++ to binary is done by a C | C++ compiler.
Re: 1.0.0 is here
Updated the Docker images: [https://cloud.docker.com/u/nimlang/repository/docker/nimlang/nim/tags](https://cloud.docker.com/u/nimlang/repository/docker/nimlang/nim/tags)
Re: nim cannot reference libraries installed with nimble.
You probably haven't added nimble packages dir to your PATH. Also, you should install Nim with choose I'm. Scoop is awesome, but choosenim is the way to go these days.
Re: Why do I get table implementation instead of the table during compile time?
Just to clarify. It's not that repr/$ shows the wrong thing, it's that some “high level” types are being implicitly replaced with “lower level” types during compilation. And these replacements effectively disregard arg types in proc signatures. Like, even if you have an arg of type seq[SqlQuery] in a proc definition, this arg value will have type array[string] when the proc body is executed during compilation, because seq is replaced with array and SqlQuery is replaced with its string repr. Am I understanding this right?
Re: Why do I get table implementation instead of the table during compile time?
It turns our other types are not passed as I expected too. SqlQuery is passed as string, which conforms to what @jlp765 said about reprs.
Re: Why do I get table implementation instead of the table during compile time?
Weirdly, if I move the proc that generates the table to the same module with db macro definition, the table is passed properly. I'm completely lost at this point. Also, including the module with the proc definition instead of importing it helps (but feels like a dirty hack).
Re: Why do I get table implementation instead of the table during compile time?
> debugEcho is showing you the table repr debugInfo shows different things when called in different places. When called at the end of the proc that returns the table, it prints the table properly. When called downstream on the called proc result, it prints the implementation details. So, even if it prints repr, because the reprs are different in two cases, that means that the things they represent are different. > Write your own $ proc for type Table[string, SqlQuery] so that > >echo > tableSchemas2 > > gives you what you want. My goal is not to print the table or get it in a prettified string form. I need to access the table's values by key and iterate over values. I can't do that because the "table" I'm getting is not a Table really.
Why do I get table implementation instead of the table during compile time?
Hi! In Norm, I'm parsing type section at compile time and generate the db schema from it. Currently, a seq[SqlQuery] is generated with code like this: proc genTableSchema(dbObjRepr: ObjRepr, dbObjReprs: openArray[ObjRepr]): SqlQuery = ## Generate table schema for an object representation. var schema: string schema.add "CREATE TABLE $# (\n" % dbObjRepr.getTable() var columns: seq[string] for field in dbObjRepr.fields: columns.add "\t$#" % genColStmt(field, dbObjReprs) schema.add columns.join(",\n") schema.add "\n)" result = sql schema proc genTableSchemas*(dbObjReprs: openArray[ObjRepr]): seq[SqlQuery] = ## Generate table schemas for a list of object representations. for dbObjRepr in dbObjReprs: result.add genTableSchema(dbObjRepr, dbObjReprs) Run genTableSchemas is called in db macro to generate withDb macro and createTables proc inside it. Everything works fine. Now, I'd like to have more control over the generated scheme and store it as a table, not a sequence: proc genTableSchemas2*(dbObjReprs: openArray[ObjRepr]): Table[string, SqlQuery] = ## Generate table schemas for a list of object representations. for dbObjRepr in dbObjReprs: result[dbObjRepr.signature.name] = genTableSchema(dbObjRepr, dbObjReprs) debugEcho result Run I get the correct table printed with debugEcho: {"Edition": CREATE TABLE editions ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, bookId INTEGER NOT NULL REFERENCES books (id) ON DELETE CASCADE ), "Publisher": CREATE TABLE publishers ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL UNIQUE, licensed INTEGER NOT NULL ), "Book": CREATE TABLE books ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, authorEmail TEXT NOT NULL REFERENCES users (email) ON DELETE CASCADE, publisherTitle TEXT NOT NULL REFERENCES publishers (title) ), "User": CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY, email TEXT NOT NULL UNIQUE, ssn INTEGER, birthDate INTEGER NOT NULL, lastLogin INTEGER NOT NULL )} Run BUT when the table is used in macro generation, I get this instead of the generated table: template genWithDb(connection, user, password, database: string, tableSchemas, dropTableQueries: openArray[SqlQuery], tableSchemas2: Table[string, SqlQuery]): untyped {.dirty.} = ## Generate withDb templates. debugEcho tableSchemas2 Run outputs: (data: @[(hcode: 4832918131319623104, key: "Edition", val: CREATE TABLE editions ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, bookId INTEGER NOT NULL REFERENCES books (id) ON DELETE CASCADE )), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: -2021507301530313398, key: "Publisher", val: CREATE TABLE publishers ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL UNIQUE, licensed INTEGER NOT NULL )), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 3086448670947841634, key: "Book", val: CREATE TABLE books ( id INTEGER NOT NULL PRIMARY KEY, title TEXT NOT NULL, authorEmail TEXT NOT NULL REFERENCES users (email) ON DELETE CASCADE, publisherTitle TEXT NOT NULL REFERENCES publishers (title) )), (hcode: 0, key: "", val: ), (hcode: -9076128372746368988, key: "User", val: CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY, email TEXT NOT NULL UNIQUE, ssn INTEGER, birthDate INTEGER NOT NULL, lastLogin INTEGER NOT NULL )), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0, key: "", val: ), (hcode: 0
Re: How does the pass statement differ from python?
Nim's `pass` is called `discard`.
Re: Introducing Norm: a Nim ORM
In Norm 1.0.15 (released just now), you can split DC schema definition across multiple modules. In order to do that. wrap the type section you want to use in schema in `dbTypes`` macro and use ``dbFromTypes`` instead of ``db`. See example in the docs (scroll down to “Alternatively to defining...”): [https://moigagoo.github.io/norm/norm.html](https://moigagoo.github.io/norm/norm.html)
Re: Introducing Norm: a Nim ORM
Here's a PR I'm developing this feature in: [https://github.com/moigagoo/norm/pull/26](https://github.com/moigagoo/norm/pull/26) Feel free to comment.
Re: Introducing Norm: a Nim ORM
Sorry, I don't think I follow your point. Could you please try to illustrate it with some examples? Or we could connect directly and chat about it in Russian if you want.
Re: Introducing Norm: a Nim ORM
It turned out to be trickier than I thought. The thing is, we're injecting id field into every type definition under db macro. This is necessary so that we can safely rely on objects having ids, which is necessary for getOne. If we're allowing to define types separately from db macro, we can't just inject id field somewhere in another module. The solution I'm leaning towards is: * allow to create db schema from types defined elsewhere only if those types have id field, which is also int and readonly * add db pragma to help people with the previous step: types with db pragma will be injected with id * disallow mixing the two approaches: you either define the schema as body for db macro, or you pass a list of db-annotated types to a different macro (e.g. dbFromTypes).
Re: Should I include translated sources into version control?
No, you shouldn't.
Re: Introducing Norm: a Nim ORM
There's an open PR that implements dbAddObject proc that allows to add type definitions from different module to the global model definition. This may be the thing that could help you: define types in modules as you'd normally do, then glue them together in models.nim module. I'll try to implement this proc for SQLite and PostgreSQL backends tomorrow.
Re: How to write static function inside a type?????
You probably mean a static method of a class, like Python @staticmethod decorated methods. In Nim, methods are just functions called with dot syntax. And static methods are just functions that don't do anything with their object argument. What are you trying to achieve? Python and Nim are different languages with different approaches to similar tasks. In order to help you better, I need to understand your problem better.
Re: Back to Nim vs V
OP sounds like a professional offendee. Surely the term "fascism" was used in a broader sense than you're sticking to. Replace it with "totalitarianism" if you feel better this way. Anyway, that’s cheap word picking irrelevant to the topic discussed. I believe the thread should be removed, and OP banned.
Re: Introducing Norm: a Nim ORM
Keeping you updated on Norm progress. * bool fields can be stored without custom parser or formatter. In SQLite, they are stored as 1 and 0, in PostgreSQL native BOOLEAN type is used. * times.DateTime fields are now also supported out of the box! In SQLite, they are stored as epoch timestamps, and in PostgreSQL native TIMESTAMP WITH TIME ZONE is used. Changelog: [https://github.com/moigagoo/norm/blob/develop/changelog.md](https://github.com/moigagoo/norm/blob/develop/changelog.md) As before, you are free to use a custom parser and formatter for any type. These are just sane defaults. Also, one breaking change was introduced in formatIt pragma for SQLite backend: the expression in the pragma must explicitly evaluate to DbValue, implicit conversion has been removed. Thanks everybody who helped by opening issues, sharing feedback, and contributing code to the project. The next big milestone is supporting NULL values in PostgreSQL, which is unfortunately blocked by ndb progress.
Re: timezone in unit tests
Use times.format with explicitly defined time zone or, which I think is better, store everything in UTC and ensure that by calling times.utc.
Re: karax navigation / redirect
Although I am Russian and can understand what you're saying, please keep it English on this forum. Rules are rules, and it's our responsibility as community members to keep the information universally available to everyone. Dominik is Polish and Andreas is German but they write and speak English since English is the lingua franca in IT today. Let's follow their example. I haven't tried Elm but I'm guessing the apparent complexity comes from its strictly functional nature. I.e. you can't just update the current URL, you have to pass the state to a function that returns a new state, with the new URL. You can do the same dance with Karax, too. But there's probably no need. Also, I don't quite know how to update the current page URL in Karax. You probably can just wrap window.location.href and set it to the needed value. Maybe @Araq will join the thread and give the right answer.
Re: karax navigation / redirect
In general, you don't change the state of the page with redirects in SPAS. You just render the needed state and update the URL.
Re: optional params before `untyped` body
I am so interested in knowing the answer to this one. Couldn't find a way to do that, had to use overloading. Works fine but feel like a hack rather than an idiomatic solution.
Re: Sponsors page bugged?
I agree. Doesn't look right despite being technically valid.
Re: Introducing Norm: a Nim ORM
I have some great news: Norm 1.0.11 supports inserting and retrieving NULL values for SQLite databases. This was made possible thanks to the great [ndb](https://github.com/xzfc/ndb.nim) module. The transition from std db_sqlite to ndb/sqlite was really smooth. I can't wait to see ndb replace all db_* modules in stdlib. As soon as ndb supports PostreSQL, we'll be able to port norm/postgres to it as well, which will make NULL support universal.
Re: Nim v0.20.0 is here (1.0 RC)
I've uploaded a new kind of Docker image to the Hub, based on choosenim instead of manually built binaries: [https://cloud.docker.com/u/nimlang/repository/docker/nimlang/choosenim](https://cloud.docker.com/u/nimlang/repository/docker/nimlang/choosenim) So, if you need an image for Nim 0.20.0 and don't care that much about its size, feel free to pull nimlang/choosenim. If you need devel version, just add choosenim devel to your Dockerfile.
Re: How to set toolchains for cross compilation?
WSL provides a nice convenient way to compile on Linux.
Re: Nim v0.19.6 released
Updated Docker images: [https://hub.docker.com/r/nimlang/nim/tags](https://hub.docker.com/r/nimlang/nim/tags)
Re: Introducing Norm: a Nim ORM
A quick update about the project. Thanks to [alaviss](https://github.com/alaviss), SQLite backend supports onUpdate and onDelete pragmas, foreign key handling now works (even with multiple FKs). getOne can retrieve a record not only by ID, but also by condition. getMany and getOne procs now support safe value substitution when constructing queries, so you can safely pass user-provided data to it. There's a breaking change: instead of `where` and `orderBy`, we now have a single `cond` arg. Feel free to use, report issues, and contribute: [https://github.com/moigagoo/norm](https://github.com/moigagoo/norm)
Re: nimpretty non installed by choosenim stable
> Nimpretty does ship with Nim. No it's not: $ wget https://nim-lang.org/download/nim-0.19.4_x64.zip $ unzip nim-0.19.4_x64.zip $ ls nim-0.19.4/bin/*.exe nim-0.19.4/bin/nim.exe* nim-0.19.4/bin/nimble.exe* nim-0.19.4/bin/nimgrab.exe* nim-0.19.4/bin/nimgrep.exe* nim-0.19.4/bin/nimsuggest.exe* nim-0.19.4/bin/vccexe.exe* Run > Not sure what you mean here. Here you suggest moving nimpretty to a separate package: [https://github.com/nim-lang/Nim/pull/7531#issuecomment-379495089](https://github.com/nim-lang/Nim/pull/7531#issuecomment-379495089) I agree with your proposal, but it seems like it was never implemented.
Re: nimpretty non installed by choosenim stable
On a separate note, Nim itself could ship with nimpretty since its already in the same repo anyway. This idea was dismissed in favor of moving nimpretty into a separate nimble package but that necer happened. And if that's the plan, than why aren't we following the same decision for choosenim?
Re: nimpretty non installed by choosenim stable
What glibc version is required? Should both Linux and Windows versions be built with it?
Re: nimpretty non installed by choosenim stable
Automated builds are great but I can't see how we can set up them fast, especially Windows builds. However, I can compile Windows and Linux 32 and 64 bit versions right now and upload them to the repo. If someone could compile an OSX build, we could call it a release and think about automating the process later.
Re: nimpretty non installed by choosenim stable
Also, it seems that Linux and OSX builds are already automated by Travis: [https://github.com/dom96/choosenim/blob/master/.travis.yml](https://github.com/dom96/choosenim/blob/master/.travis.yml) Does that mean that only Windows builds are missing?
Re: nimpretty non installed by choosenim stable
Can I help? Are there pending PRs to be reviewed that you want included in the new release? Maybe, critical issues?
Re: nimpretty non installed by choosenim stable
What's blocking a new choosenim release?
Re: getch() vs Cyrillic on Windows.
Hi! No need to get aggressive :-) There are bugs out there, no doubt about that. Any help reporting and fixing them is very much appreciated. Could you please [report the issue](https://github.com/nim-lang/Nim/issues/new?template=bug_report.md)?
Re: Introducing Norm: a Nim ORM
Thanks for the idea! Sounds easy to implement. How do I store NULLs in an object though? Maybe, allow fields to be nil besides their own type?
Re: Introducing Norm: a Nim ORM
Thanks for the links! I didn't know about nim_sqlbuilder, I may switch to it instead of using my own `rowutils` module.