Commonalities for MS SQL and MySQL Magic data adapters
Repo polterguy/magic.data.common, read from GitHub 15 h ago. polterguy has not joined Take My Repo.
polterguy/magic.data.common is a public repo on GitHub by polterguy. Commonalities for MS SQL and MySQL Magic data adapters. It declares the GPL-3.0 license on GitHub. It is written mainly in C#, has 3 stars and last changed on 2024-01-22. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
The magic.data.commonproject is the generic data adapter, that transform dynamically from a lambda node structure into SQL, and polymorphistically invokes your specialised data adapter, resulting in SQL statements executed towards your database type of choice. In addition, it contains helper slots to give you more "raw" database access, in addition to slots helping you to open database connections, create transactions, execute SQL, etc.
These slots never executes SQL towards your data adapter, but rather simply generates your SQL, and returns the results of the SQL generation process back to you. They're mostly intended for debugging purposes, and/or learning purposes, and can be interchanged with their [data.xxx] equivalent, and/or their [mysql.xxx]/[mssql.xxx]/[pgsql.xxx] equivalent, etc. You can substitute these slots with for instance [data.xxx] if you wish to actually execute some SQL towards your database adapter of choice.
All of the [data.xxx] slots are actually just polymorphistically evaluating your specialised adapter's slots, such as for instance [data.connect], that will invoke [mysql.connect] if this is your default database. However, all of these lots can also be given an explicit [database-type] argument, being for instance "mssql", allowing you to choose a database type explicitly as you invoke it.
If you don't provide an explicit [database-type] argument to these slots, the default database
type will be retrieved from your "appsettings.json" file, from the magic:databases:default value,
and substitute the "data" parts with the value found from your configuration setting, to invoke
your specialised implementation. For instance, if you're using MySQL as your default database type,
and you invoke for instance [data.connect], this will transform into an invocation to [mysql.connect],
allowing you to use generic database slot invocations, ignoring your database type, creating the correct
SQL dialect for you automagically.
This slot will open a database connection for you. You can pass in a complete connection string (not recommended),
or only the database name if you wish. If you pass in only the database name, the generic connection string for your
database type of choice from your "appsettings.json" file will be used, substituting its {database} parts
with the database of your choice.
Inside of this slot, which actually is a lambda [eval] invocation, you can use any of the other slots, requiring
an existing and open database connection to function. You can see an example below.
data.connect:sakila
data.read
table:actor
Since the [data.connect] slot actually takes a lambda object, you can also add any amount
of other lambda invocations inside of the lambda object supplied to the slot, allowing you to for instance
create loops, conditional executions, etc, inside of your invocation to [data.connect]. This is also
true for all other slots taking a lambda object, such as for instance [data.transaction.create].
Inside your lambda object, an invocation towards your database such as e.g. [data.read], will be
using this database connection, as long as the type of database is matching. The database connection will
be kept open, and implicitly used, for the entirety of the lambda object. If you need another database
connection inside of your lambda object, you'll need to nest [data.connect] invocations.
You can also explicitly choose which connection string to use as you open a connection, by separating the
connection string and the database name by a | symbol, and wrapping your entire value inside
of brackets. If you have a connection string in your "appsettings.json" file named for instance "foo",
and this connection string points to a server instance having a database named "bar", you could open
a connection to this database using something resembling the following.
data.connect:[foo|bar]
This is why your connection strings should contain the {database} as a generic argument, since the slot
substitutes the {database} parts dynamically as you create new connections. Below is an example of such
a connection string configuration setting.
"generic": "Server=localhost\\SQLEXPRESS;Database={database};Trusted_Connection=True;"
This slot allows you to pass in any arbitrary SQL you wish, and evaluate it to a DataReader, and return
all records as a lambda object. You can find an example below.
data.connect:sakila
data.select:select first_name, last_name from actor limit 5
Assuming you have the "sakila" database from Oracle installed in your database, and your default database type is MySQL, the result of the above will end up looking like the following.
data.connect
data.select
""
first_name:PENELOPE
last_name:GUINESS
""
first_name:NICK
last_name:WAHLBERG
""
first_name:ED
last_name:CHASE
""
first_name:JENNIFER
last_name:DAVIS
""
first_name:JOHNNY
last_name:LOLLOBRIGIDA
This slot requires SQL resembling your specialised database type of dialect, and will not in any ways transpile the SQL towards your specific underlaying database type's SQL dialect. If you can, you should rather use [data.read], to avoid lockin towards a specific database vendor's SQL dialect. You can also select multiple result sets if you have batch type of SQL statements, containing multiple SQL statements, and you want to return the result of all SQL statements you're executing. You do this by providing a [multiple-result-sets] argument and set its value to boolean true. If you do this, the slot will return an array of arrays, one outer array for each result set your SQL generates. Below is an example.
data.select:"select * from table1; select * from table2;"
multiple-result-sets:bool:true
Which would result in something resembling the following.
data.select
""
""
field1:foo1
field2:bar1
""
field1:foo2
field2:bar2
""
""
field1:foo1
field2:bar1
""
field1:foo2
field2:bar2
This slot is similar to the [data.select] slot, but will only return one value as the value of its node after execution. This slot is typically used for aggregate results. You can see an example below.
data.connect:sakila
data.scalar:select count(*) from actor
After execution, your result will resemble the following.
data.connect
data.scalar:long:200
Yet again you should prefer the [data.*] slots if you can.
This slot should be used if you don't expect any type of result at all, such as in for instance delete or update invocations, where you don't care about the result of the operation. You can find an example below.
data.connect:sakila
// Notice, will throw! (hopefully!)
data.execute:delete from non_existing_table
Yet again, prefer [data.delete] if you can.
Although you should be careful with database transactions, sometimes you really need them. For those cases you can use the following 3 slots to create, rollback, and/or commit transactions towards your underlaying database.
Notice - The default logic for a database transaction, is that unless it's explicitly committed before leaving scope, it will roll back by default. Below is an example of a transaction that will rollback, since it's not explicitly commited before leaving scope.
data.connect:sakila
data.transaction.create
data.execute:delete from film_actor
/*
* If you uncomment the line below the
* transaction will be committed, resulting
* in that everything from your film_actor
* table will be deleted.
*/
//data.transaction.commit
data.connect:sakila
/*
* Notice, this still returns 5462 items, since
* transaction was implicitly rolled back above.
*/
data.scalar:select count(*) from film_actor
A transaction typically follows your connection, implying to count items after the transaction has been rolled back, we'll need a new connection, as the above example illustrates.
All of these slots simply generates SQL for you, using the generic SQL dialect syntax, which might or might not work for your database adapter of choice. This allows you to create SQL statements without executing anything towards your database. This allows you to play around with the syntax, to understand how it works, and see how some semantic graph object results in an SQL statement before using it. All of these slots have [data.*] equivalent slots, which again polymorphistically invokes your specialised data adapter's equivalent, and/or can be parametrised with a database type - Which again resolves to the [mysql.*] equivalent if you supply "mysql" as your [database-type], and/or MySQL is your default database type as configured in your "appsettings.json" file. Hence, the documentation for these slots is also the documentation for your [data.*] slots.
This slot will generate the SQL necessary to insert a record into a database for you. Besides the table argument, this slot can only be given one argument, which is [values]. Below is an example of usage.
sql.create
table:table1
values
field1:howdy
field2:world
Notice, to avoid SQL injection attacks, this slot will always return parameters expected to be passed in from any potentially malicious clients as SQL parameters - Hence, the complete returned value of the above Hyperlambda will be as follows.
sql.create:insert into 'table1' ('field1', 'field2') values (@0, @1)
@0:howdy
@1:world
The basic idea is that everything that might be dynamically injected into your data access layer,
should be consumed as SqlParameters, or something equivalent, to prevent SQL injection attacks
towards your database. This is true for all arguments passed in as data for all slots in the project.
The slot will in its specialized implementations return the ID of the inserted record if possible,
unless you explicitly parametrize it with a [return-id] argument and set its value to boolean
false.
This slot requires only one mandatory argument, being your table name. The slot creates a select SQL statement for you. An example can be found below.
sql.read
table:foo
The above will result in the following SQL returned to you. If you're using the special implementations, such as e.g. [data.read], and/or [mssql.read] - The returned SQL might vary according to your dialect. But the results of executing the SQL will be the same.
select * from 'foo' limit 25
To avoid accidentally exhausting your database, this slot will by default limit your result set to 25 records unless explicitly overridden by your code with a [limit] argument. You can optionally supply the following arguments to this slot.
For instance, to select only the "field1" column and the "field2" column from "table1", and ordering descendingly by "field3" - You can use something resembling the following.
sql.read
table:table1
columns
field1
field2
order:field3
direction:desc
This will result in the following SQL returned.
select 'field1','field2' from 'table1' order by 'field3' desc limit 25
The [direction] argument can only be either "asc" or "desc", implying ascending or descending. You can also supply multiple ordering columns, by separating them by ",". See an example below, which also specifies what table to use while ordering your results.
sql.read
table:table1
order:table1.field1, table1.field2
The above will result in the following SQL.
select * from 'table1' order by 'table1'.'field1' asc,'table1'.'field2' asc limit 25
And finally you can provide the [direction] argument on separate [order] arguments, such as the following illustrates.
sql.read
table:table1
order:field1
direction:asc
order:field2
direction:desc
If you do, the ordering is sequentially applied.
You can also create aggregate results, by simply adding your aggregate as your column, such as the following illustrates. The reasons why this works, is because if the SQL generator finds a paranthesis in your column declaration, it will simply ignore parsing that column altogether, and directly inject it into the resulting SQL's columns declaration.
sql.read
table:table1
limit:-1
columns
count(*)
as:count
The above will result in the following SQL.
select count(*) as count from 'table1'
By setting [limit] to "-1", like we do above, we avoid adding the limit parts to our SQL. Unless you explicitly specify a limit, the default value will always be 25 to avoid accidentally exhausting your database, and/or web server, by selecting all records from a table with millions of records.
To page your [sql.read] results, use [limit] and [offset]
polterguy/magic.data.common is a public repo on GitHub by polterguy. Commonalities for MS SQL and MySQL Magic data adapters.
It declares the GPL-3.0 license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2024-01-22. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run magic.data.common. What is known comes from GitHub. It declares the GPL-3.0 license on GitHub. Its last change was on 2024-01-22. It has 3 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.