Comments (10)
Should be something like
data TableT f =
Table { _column1 :: C f Int
, _column2 :: C f Text }
deriving Generic
deriving instance Beamable TableT
instance Table TableT ...
data Table2T f =
Table2 { _column3 :: C f Text }
deriving Generic
deriving instance Beamable Table2T
instance Table Table2T ...
data Db entity =
Db { _tbl1 :: entity (TableEntity TableT)
, _tbl2 :: entity (TableEntity Table2) }
deriving Generic
instance Database Db
db :: DatabaseSettings be Db
db = autoDbSettings
insert (_tbl1 db) $
insertFrom $ select $
fmap (\(Table2 column3) -> Tablet (charLength_ column3) column3) $
all_ (_tbl2 db)
from beam.
In my case _tbl1
has a primary key so I wanted to use default_
to not specify that. However, you can't select DEFAULT
on the RHS.
from beam.
@3noch That's right. That's a SQL limitation. Are you asking about using projections (like INSERT INTO tbl(field1, field2,...)
) in insert
? If so, you're right, there's no current way to do this, but we can add this in if you need it
from beam.
Yes that must be what I'm looking for, a way to do a projection on the FROM SELECT
so that I can specify some (but not all) of the target table columns.
from beam.
I think we could potentially do a syntax along the lines of:
insertFields (_tbl1 db) (\tbl -> _field1 tbl) $ insertFrom $ select $ fmap (\(Table2 column3) -> column3) $ all_ (_tbl2 db)
So basically you specify the tbl to insert into, a projection from that table, and then we'd rework the types a bit to allow insertFrom
to return arbitrary projections instead of tables only. Would that work?
from beam.
in the case of falling back to default isn't that what Auto Nothing
is for or does that not help in this case?
from beam.
Auto Nothing
is a beam convenience. It's unrepresentable in general in SQL
from beam.
@tathougies I have very little opinion or wisdom to offer regarding how you represent this in Beam. I don't quite see how your example would work but I don't think that means much. In particular, the trick is saying how fields from two different tables would correspond. That doesn't seem trivial to me.
from beam.
Many months later, but insertOnly
is now a thing. From the docs:
runInsert $
insertOnly (invoice chinookDb)
(\i -> ( invoiceCustomer i, invoiceDate i, invoiceBillingAddress i, invoiceTotal i ) ) $
insertFrom $ do
c <- all_ (customer chinookDb)
-- We'll just charge each customer $10 to be mean!
pure (primaryKey c, currentTimestamp_, customerAddress c, as_ @Scientific $ val_ 10)
inserts values only into the customer, date, billing address, and total columns.
from beam.
Sweet!
from beam.
Related Issues (20)
- Lens example in tutorial does not work HOT 1
- GHC 9.6 failures HOT 3
- beam-sqlite: No `instance HasSqlEqualityCheck Sqlite Day` HOT 1
- WHERE clauses are silently dropped if there is no FROM HOT 1
- beam-sqlite: support for `LIKE` + `ESCAPE` ? HOT 1
- free-5.2 not allowed
- vector-0.13 not allowed
- primitive-0.8 not allowed HOT 3
- How to get primary key type? HOT 1
- Subquery without aggregation
- Multicolumn aggregate HOT 1
- Is there any way to reuse a `ToField`, `FromField` definitions from sqlite-simple? HOT 1
- Precise type for `max_` aggregate function
- Postgres column doesn't roundtrip for type `Maybe (Vector Text)`
- Outdated dependencies HOT 4
- Passing `Double`s to `val_` sometimes leads to runtime errors
- run-time error "column t0.res0 does not exist" HOT 1
- Insert result of an insert
- Run-time error "window function first_value requires an OVER clause" HOT 1
- run-time error: operator does not exist: timestamp without time zone < text
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beam.