has anybody tried using postgres from squint?
why would it be different from squint than any other JS language?
It shouldn't be, but I'm having trouble translating this bit
const { Pool } = require('pg');
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: 'secret',
port: 5432
});
I tried
(ns foo
(:require
["pg" :as pg :refer [Pool]]))
(def pool
(Pool.
{:user "postgres"
:host "localhost"
:port 5432
:database "postgres"
:password "secret"}))
js version is happy, but I get globalThis.foo.Pool is not a constructor in squint nrepl
am I just doing something silly here?
pg looks like it's an object and I can conosole.log it
and it has a Pool: [class BoundPool extends Pool], on it
so looking at compiled js, looks like it's require vs import import { Client, Pool } from 'pg';
what's the squint synonym for const { Pool } = require('pg');?
(ns foo
(:require
["pg" :as pg]))
(def Pool pg.Pool)
compiles to this
import * as pg from 'pg';
var Pool = pg.Pool;
but the pool is nilTry adding $default to the lib string
hmm no dice ["pg$default" :as pg :refer [Pool]]
Or try console log on pg and check whatever is printed there
but there is default in the output
this is what I get with pg
[Module: null prototype] {
default: PG {
defaults: {
host: 'localhost',
user: 'yogthos',
database: undefined,
password: null,
connectionString: undefined,
port: 5432,
rows: 0,
binary: false,
max: 10,
idleTimeoutMillis: 30000,
client_encoding: '',
ssl: false,
application_name: undefined,
fallback_application_name: undefined,
options: undefined,
parseInputDatesAsUTC: false,
statement_timeout: false,
lock_timeout: false,
idle_in_transaction_session_timeout: false,
query_timeout: false,
connect_timeout: 0,
keepalives: 1,
keepalives_idle: 0,
parseInt8: [Setter]
},
Client: [class Client extends EventEmitter] {
Query: [class Query extends EventEmitter]
},
Query: [class Query extends EventEmitter],
Pool: [class BoundPool extends Pool],
_pools: [],
Connection: [class Connection extends EventEmitter],
types: {
getTypeParser: [Function: getTypeParser],
setTypeParser: [Function: setTypeParser],
arrayParser: [Object],
builtins: [Object]
},
DatabaseError: [class DatabaseError extends Error],
escapeIdentifier: [Function: escapeIdentifier],
escapeLiteral: [Function: escapeLiteral]
}
}I’ll try in a bit
thanks
I can make a pr with an example once we get it working to document the magic 🙂
$ npx squint --show -e '(ns foo (:require ["pg$default" :as pg])) (js/console.log pg.Client)'
import * as squint_core from 'squint-cljs/core.js';
import pg from 'pg';
console.log(pg.Client);
[class Client extends EventEmitter] {
Query: [class Query extends EventEmitter]
}$ npx squint --show -e '(ns foo (:require ["pg$default" :as pg])) (js/console.log pg.Pool)'
import * as squint_core from 'squint-cljs/core.js';
import pg from 'pg';
console.log(pg.Pool);
[class BoundPool extends Pool]I think you're hitting a bug in squint when doing both $default and :refer
since it looks like :refer is still destructuring on the object that wraps default
$ npx squint --show -e '(ns foo (:require ["pg$default" :as pg :refer [Pool]])) (js/console.log Pool)'
import * as squint_core from 'squint-cljs/core.js';
import pg from 'pg';
import { Pool } from 'pg';
console.log(Pool);
file:///private/tmp/dude/.tmp4ras1Q/squint.mjs:3
import { Pool } from 'pg';ah yeah makes sense
for now just use (def Pool pg.Pool) or so
sounds good, I'll add an issue to track it
and can confirm stuff is working with pg.Pool
@borkdude oh and another quick question, is there a hiccup parser accessible outside #jsx that could be used to return html server side?
you can use the #html tag to produce html strings in the same manner as #jsx
ah excellent
exactly what I was looking for
I should have a useful example of a minimal server talking to pg and producing html I can add in a bit here
for a bit of context, I'm experimenting with porting aws lambdas I have running on bb to squint to see how resource usage compares
nice :)
so far it's going well, my utter lack of familiarity with the js ecosystem is the main stumbling block 🙂
chatgpt to the rescue? ;)
I have been leaning on https://www.phind.com/ quite a bit 🙂
llms work pretty well for this sort of thing where I know roughly what I'm trying to do, but not the exact syntax