hi im just testing xata, i need to
hi im just testing xata, i need to create a inventory management system for my business, you guys recommend me xata? xata have branches? like one branch for dev and another for staging and one for prod?
46 Replies
Hi and welcome! What languages and frameworks are you planning to use?
Xata offers SDKs for TypeScript and Python and is well tested with frontend frameworks such as NextJS.
Xata does have branches! Every database comes with the default
main
branch, but you can create new branches and perform migrations or merge them together from the UI or CLI (xata pull / xata push commands).
In case you'd prefer to use SQL, then that's possible as well from the SDK or REST API https://xata.io/docs/sdk/sql/overview.
We also offer a new Beta database type that is Postgres-Enabled so you can connect from the Wire protocol (meaning, using any client that supports native postgres connectivity) - but be aware that this database type doesn't support merging branches yet.
The Free plan allows you to create 10 branches in your Workspacehi i will use react so i just need rest part of the db
Great, then the TypeScript SDK will be a good fit for your use case.
Each branch acts as a standalone instance of a database in terms of rate limits (https://xata.io/docs/concepts/pricing#concurrency-limit) so you can work with dev/staging without affecting production workloads (main branch)
and what if i have already a postgresql db with defined columns, how i move all those and the data to xata?
With the current production dbs, the easiest way to migrate from Postgres is with CSV export/import. Both the Xata UI and the CLI offer CSV import options (https://xata.io/docs/csv-data/import-data).
With the Beta postgres-enabled databases, you can use standard postgres tooling (pg_dump/pg_restore https://xata.io/docs/postgres#export) to bring your data to Xata. Note that you will additionally neeed to "Adapt your tables" in the Xata UI if you use this method, for the REST API to work. This introduces additional xata-internal columns to your tables, which are necessary for the SDK and Xata's added features (search, aggregations).
sounds good, and how i can manage join two tables with xata?
You can either
- do joins using actual SQL (it's possible even with the TS SDK, proxied over HTTP)
- use Xata's special-purpose link column type: https://xata.io/docs/concepts/data-model#link which links records between tables based on the record id.
how i do it with actual sql? or the question is which method you recommend
im using rest to get data and fill a table in rest
in react
There are various options:
- We have a Kysely integration for typed SQL JOIN statements. https://xata.io/docs/sdk/get#many-to-many-relationships
- If you don't mind about types, use plain SQL over HTTP:
https://xata.io/docs/sdk/sql/overview
SELECT vehiculos.id,vehiculos.marca,vehiculos.modelo,vehiculos.year,vehiculos.placa,vehiculos.vin,vehiculos.imagen,CONCAT(users.first_name, ' ' , users.last_name) as asignado,users.id as idcolaborador,seguro_expiracion,vehiculos.usuario_crea
FROM vehiculos JOIN users ON users.id = vehiculos.asignado_user_id order by id i got this already but i want to use rest with the link table column i already got users table in xata
FROM vehiculos JOIN users ON users.id = vehiculos.asignado_user_id order by id i got this already but i want to use rest with the link table column i already got users table in xata
In order to create a link column, linking a user record to a vehiculos record, the vehiculos table needs to be created first and each record in it must have an id column. If you import from CSV and your file already has an id column, xata will use that, otherwise it adds an id column and autogenerates values for each row.
Then, the id values of vehiculos records need to be set in the users table, in the link column that links a user to a vehicle. It cannot happen on-the-fly, relations need to be established by inserting an id of a vehicle to the relevant column of each user record.
Alternatively, with plain SQL you can do the join exactly as you described - without using the link column.
Yea inside vehiculos table i already got a column name asignado_id and that id is linked to the column id from users table
Thats why this query works good
Great, then you can use a call like this to "expand" a vehiculos record to bring the linked user content:
https://xata.io/docs/sdk/get#selecting-columns-from-the-linked-tables
You can also do the reverse, find a linking vehicule from the users table with the backwards relation operator
<-
https://xata.io/docs/concepts/data-model#links-and-relationshipsbut with rest how i can do it?
first i need to create inside xata a link table column?